Class: String

Inherits:
Object show all
Defined in:
lib/rstore/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#is_f?Boolean

Checks if String represents a Float.

Returns:

  • (Boolean)


13
14
15
# File 'lib/rstore/core_ext/string.rb', line 13

def is_f?
  !!(self =~ /^[-+]?[0-9,]+\.[0-9]+$/)
end

#is_i?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/rstore/core_ext/string.rb', line 8

def is_i?
  !!(self =~ /^[-+]?[0-9,]+$/)
end

#to_numObject



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

#unquoteObject



4
5
6
# File 'lib/rstore/core_ext/string.rb', line 4

def unquote
  self.gsub(/(^"|"$)/,"").gsub(/""/,'"')
end

#url?Boolean

Returns:

  • (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