Module: MyJohnDeere::JSONAttributes::InstanceMethods

Defined in:
lib/myjohndeere/json_attributes.rb

Instance Method Summary collapse

Instance Method Details

#setup_attributes(json_data) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/myjohndeere/json_attributes.rb', line 20

def setup_attributes(json_data)
  return if self.class.json_attributes.nil?
  self.class.json_attributes.each do |attrib|
    attrib = attrib.to_s
    val = json_data[attrib]
    if /(date)|(timestamp)/i.match(attrib) then
      # try to parse it
      val = Time.parse(val) rescue val
    end
    instance_variable_set("@#{attrib.underscore}", val)
  end
end