Sha256: 64a4e829115d72af5c1140c10af9da1989633204cf7f6d228686c8e61a675ba1
Contents?: true
Size: 685 Bytes
Versions: 1
Compression:
Stored size: 685 Bytes
Contents
module Ensurance class Time def self.ensure(thing) case thing.class.name when "NilClass" thing when "Time" thing when "Date" thing.beginning_of_day when "Integer", "Float" ::Time.at(thing) when "String" if thing.to_i.to_s == thing ::Time.at(thing.to_i) elsif thing.to_f.to_s == thing ::Time.at(thing.to_f) else ::Time.parse(thing) end else if thing.respond_to?(:to_time) thing.to_time else raise ArgumentError.new("Unhandled Type for Time to ensure: #{thing.class}") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ensurance-0.1.0 | lib/ensurance/time.rb |