Class: String
Instance Method Summary collapse
-
#is_f? ⇒ Boolean
Checks if String represents a Float.
- #is_i? ⇒ Boolean
- #to_num ⇒ Object
- #unquote ⇒ Object
- #url? ⇒ Boolean
Instance Method Details
#is_f? ⇒ Boolean
Checks if String represents a Float.
13 14 15 |
# File 'lib/rstore/core_ext/string.rb', line 13 def is_f? !!(self =~ /^[-+]?[0-9,]+\.[0-9]+$/) end |
#is_i? ⇒ Boolean
8 9 10 |
# File 'lib/rstore/core_ext/string.rb', line 8 def is_i? !!(self =~ /^[-+]?[0-9,]+$/) end |
#to_num ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/rstore/core_ext/string.rb', line 17 def to_num if self.is_f? self.to_f elsif self.is_i? self.to_i else end end |
#unquote ⇒ Object
4 5 6 |
# File 'lib/rstore/core_ext/string.rb', line 4 def unquote self.gsub(/(^"|"$)/,"").gsub(/""/,'"') end |
#url? ⇒ Boolean
27 28 29 30 31 32 33 34 |
# File 'lib/rstore/core_ext/string.rb', line 27 def url? # http://daringfireball.net/2010/07/improved_regex_for_matching_urls url_regex = /^((?:https?:\/\/|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+ (?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/x !!(self =~ url_regex) end |