Class: String

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

Instance Method Summary collapse

Instance Method Details

#float?Boolean

Check if String is a valid float

Returns:

  • (Boolean)


19
20
21
# File 'lib/utilities/string.rb', line 19

def float?
  !!Float(self) rescue false
end

#hour_to_float(separator = ':') ⇒ Object

Transform a string of format HH:MM into a float representing an hour



13
14
15
16
# File 'lib/utilities/string.rb', line 13

def hour_to_float(separator=':')
  m, s = self.split(separator).map(&:to_f)
  m + (s / 60)
end

#to_dateObject

Transform self to a Date



3
4
5
# File 'lib/utilities/string.rb', line 3

def to_date
  Date.parse(self)
end

#to_timeObject

Transform self to a Time



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

def to_time
  Time.parse(self)
end