Class: String
Instance Method Summary collapse
-
#float? ⇒ Boolean
Check if String is a valid float.
-
#hour_to_float(separator = ':') ⇒ Object
Transform a string of format HH:MM into a float representing an hour.
-
#to_date ⇒ Object
Transform self to a Date.
-
#to_time ⇒ Object
Transform self to a Time.
Instance Method Details
#float? ⇒ Boolean
Check if String is a valid float
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_date ⇒ Object
Transform self to a Date
3 4 5 |
# File 'lib/utilities/string.rb', line 3 def to_date Date.parse(self) end |