module ReadMyTime::Reader
Public Instance Methods
locale_prefix()
click to toggle source
Used to localize
# File lib/read_my_time/reader.rb, line 28 def locale_prefix 'read_my_time' end
seconds_in_words(opts = {})
click to toggle source
# File lib/read_my_time/reader.rb, line 4 def seconds_in_words(opts = {}) seconds_int = self.to_i return '' if seconds_int <= 0 # options by default opts[:skip_seconds] = false if opts[:skip_seconds].nil? unit_time_dividers.each_with_object([]) do |(unit_time, divider), s| if seconds_int > 0 seconds_int, rest = seconds_int.divmod(divider) if rest.nonzero? && !(unit_time == :seconds && opts[:skip_seconds]) word = I18n.t(unit_time.to_s, count: rest, scope: locale_prefix) s.unshift("#{rest} #{word}") end end s end.join(' ') end
unit_time_dividers()
click to toggle source
# File lib/read_my_time/reader.rb, line 32 def unit_time_dividers { seconds: 60, minutes: 60, hours: 24, days: 365 } end