Module: Kernel

Defined in:
lib/timerage.rb

Instance Method Summary collapse

Instance Method Details

#Timerage(time_or_time_interval_ish) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/timerage.rb', line 48

def Timerage(time_or_time_interval_ish)
  thing = time_or_time_interval_ish

  case thing
  when ->(x) { x.respond_to? :to_time_interval }
    thing

  when ->(x) { x.respond_to? :exclude_end? }
    Timerage::TimeInterval.from_range(thing)

  when ->(x) { x.respond_to? :to_str }
    Timerage.parse_iso8601(thing.to_str)

  when ->(x) { x.respond_to? :to_time }
    thing.to_time

  else
    fail TypeError, "unable to coerce #{thing} to a time or interval"

  end
end