Class: Timestamps
- Inherits:
-
Object
- Object
- Timestamps
- Defined in:
- lib/wonko_the_sane/timestamps.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get(uid, version, default = nil) ⇒ Object
-
#initialize ⇒ Timestamps
constructor
A new instance of Timestamps.
Constructor Details
#initialize ⇒ Timestamps
Returns a new instance of Timestamps.
2 3 4 |
# File 'lib/wonko_the_sane/timestamps.rb', line 2 def initialize @json = WonkoTheSane.data_json 'timestamps.json' end |
Class Method Details
.get(uid, version, default = nil) ⇒ Object
26 27 28 29 |
# File 'lib/wonko_the_sane/timestamps.rb', line 26 def self.get(uid, version, default = nil) @me ||= Timestamps.new @me.get uid, version, default end |
Instance Method Details
#get(uid, version, default = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/wonko_the_sane/timestamps.rb', line 6 def get(uid, version, default = nil) if @json[uid.to_sym] && @json[uid.to_sym][version.to_sym] @json[uid.to_sym][version.to_sym] elsif default.nil? raise 'No timestamp available for ' + uid + ': ' + version elsif default.is_a? String if default.to_i.to_s == default return default.to_i else return DateTime.parse(default).to_time.to_i end elsif default.is_a? Fixnum return default elsif default.is_a? Float return default.to_i else raise 'InvalidTimeFormat' end end |