Class: String

Inherits:
Object show all
Defined in:
lib/nested_hash_tricks/main.rb

Instance Method Summary collapse

Instance Method Details

#date?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
67
68
# File 'lib/nested_hash_tricks/main.rb', line 62

def date?
  matches = (self =~ /\/\d+\//) || (self =~ /-\d+-/)
  matches2 = self =~ /^[ \d\-\/:]+$/
  !!(matches && matches2 && Time.parse(self))
rescue
  return false
end

#num?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/nested_hash_tricks/main.rb', line 59

def num?
  size > 0 && self =~ /^[\d\.]*$/
end

#tmoObject



72
73
74
75
76
77
78
79
80
# File 'lib/nested_hash_tricks/main.rb', line 72

def tmo
  if num? 
    to_f.tmo 
  elsif blank?
    nil
  else
    self
  end
end

#to_timeObject



69
70
71
# File 'lib/nested_hash_tricks/main.rb', line 69

def to_time
  Time.parse(self)
end