Module: Kernel

Defined in:
lib/timerage.rb

Instance Method Summary collapse

Instance Method Details

#Timerage(time_or_time_interval_ish) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/timerage.rb', line 35

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.new(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