class Parser
Parser
others types to value
Public Class Methods
new(only_hours = true)
click to toggle source
# File lib/tempus/parser.rb, line 5 def initialize(only_hours = true) @only_hours = only_hours end
Public Instance Methods
parse(value)
click to toggle source
# File lib/tempus/parser.rb, line 9 def parse(value) @value = value if @value.is_a?(String) from_string.to_f elsif @value.is_a?(Time) from_time.to_f else @value.to_f end end
Private Instance Methods
from_string()
click to toggle source
# File lib/tempus/parser.rb, line 29 def from_string str = @value.to_s.split(':') value = 0 %i[hours minutes seconds].each_with_index do |m, i| value += str.at(i).to_i.abs.send(m.to_s) end str.to_s.include?('-') ? value * -1 : value end
from_time()
click to toggle source
# File lib/tempus/parser.rb, line 23 def from_time return @value.to_f unless @only_hours (@value - @value.beginning_of_day).to_f end