module MyJohnDeere::JSONAttributes::InstanceMethods

Public Instance Methods

setup_attributes(json_data) click to toggle source
# 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 val =~ /\A(true)|(false)\z/i then
      val = /true/i.match(val) ? true : false
    elsif /(date)|(timestamp)|(time\Z)/i.match(attrib) then
      # try to parse it
      val = Time.parse(val) rescue val
    end
    instance_variable_set("@#{attrib.underscore}", val)
  end
end
to_s() click to toggle source
# File lib/myjohndeere/json_attributes.rb, line 35
def to_s
  the_hash = {}
  self.class.json_attributes.each do |attrib|
    the_hash[attrib] = send(attrib.to_s.underscore)
  end
  return "#{self.class}: #{the_hash}"
end