Class Duration
In: lib/chronos/durationtotext.rb
Parent: Object

Methods

new   to_s   to_text  

Constants

ToTextEn = { -(1/0.0) => proc { |s| sprintf "%d weeks ago", -s.div(604800) }, -1209600 => proc { |s| "one week ago" }, -604800 => proc { |s| sprintf "%d days ago", -s.div(86500) }, -172800 => proc { |s| "yesterday" }, 0 => proc { |s| "today" }, 86400 => proc { |s| "tomorrow" }, 172800 => proc { |s| sprintf "in %d days", (s/86400).ceil }, 604800 => proc { |s| "in one week" }, 1209600 => proc { |s| sprintf "in %d weeks", (s/604800).ceil }, }.to_a.sort

Public Class methods

[Source]

    # File lib/chronos/durationtotext.rb, line 27
27:   def initialize(seconds, months=0)
28:     @seconds = seconds
29:     @months  = months
30:   end

Public Instance methods

to_s()

Alias for to_text

[Source]

    # File lib/chronos/durationtotext.rb, line 32
32:   def to_text
33:     ToTextEn.each_cons(2) { |(v,t), (v2,t2)|
34:       return t.call(@seconds) if @seconds >= v && @seconds < v2
35:     }
36:     ToTextEn.last.last.call(@seconds)
37:   end

[Validate]