class TimeKeeper::CustomTime

Constants

TIME_FORMAT_REGEX

Attributes

time_in_str[RW]

Public Class Methods

new(time_in_str) click to toggle source
# File lib/time_keeper/custom_time.rb, line 10
def initialize(time_in_str)
  @time_in_str = time_in_str.downcase.strip
end

Public Instance Methods

in_hours() click to toggle source
# File lib/time_keeper/custom_time.rb, line 29
def in_hours
  raise "Please parse the time before extracting in hours" unless @parsed_time
  @parsed_time.hour + ((@parsed_time.min.to_f / 60) * 100).round.to_f/100
end
in_minutes() click to toggle source
# File lib/time_keeper/custom_time.rb, line 24
def in_minutes
  raise "Please parse the time before extracting in minutes" unless @parsed_time
  @parsed_time.hour * 60 + @parsed_time.min
end
in_seconds() click to toggle source
# File lib/time_keeper/custom_time.rb, line 19
def in_seconds
  raise "Please parse the time before extracting in seconds" unless @parsed_time
  @parsed_time.hour * 3600 + @parsed_time.min * 60
end
parse() click to toggle source
# File lib/time_keeper/custom_time.rb, line 14
def parse
  @parsed_time = TimeKeeper::Parser::Base.build(@time_in_str).parse
  self
end
to_s() click to toggle source
# File lib/time_keeper/custom_time.rb, line 34
def to_s
  h = (self.in_minutes.to_i / 60)
  m = (self.in_minutes.to_i % 60)
  "%.2d:%.2d" % [h,m]
end