Module: FmRest::StringDateAwareness

Defined in:
lib/fmrest/string_date.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.enable(classes: [Date, DateTime]) ⇒ Object



216
217
218
# File 'lib/fmrest/string_date.rb', line 216

def self.enable(classes: [Date, DateTime])
  classes.each { |klass| klass.singleton_class.prepend(self) }
end

Instance Method Details

#===(other) ⇒ Object

Overriding case equality method so that it returns true for FmRest::StringDate instances

Calls superclass method



212
213
214
# File 'lib/fmrest/string_date.rb', line 212

def ===(other)
  super || other.is_a?(StringDate)
end

#_parse(v, *_) ⇒ Object



190
191
192
193
194
195
196
197
198
# File 'lib/fmrest/string_date.rb', line 190

def _parse(v, *_)
  if v.is_a?(StringDateTime)
    return { year: v.year, mon: v.month, mday: v.mday, hour: v.hour, min: v.min, sec: v.sec, sec_fraction: v.sec_fraction, offset: v.offset }
  end
  if v.is_a?(StringDate)
    return { year: v.year, mon: v.month, mday: v.mday }
  end
  super
end

#parse(v, *_) ⇒ Object



200
201
202
203
204
205
# File 'lib/fmrest/string_date.rb', line 200

def parse(v, *_)
  if v.is_a?(StringDate)
    return self == ::DateTime ? v.to_datetime : v.to_date
  end
  super
end