Sha256: f0da3a7ba61ce66714d385d0095ec16ea96d40f9489f54fcaa43dea1db2bcb66

Contents?: true

Size: 901 Bytes

Versions: 23

Compression:

Stored size: 901 Bytes

Contents

module MyJohnDeere
  class APISupportItem
    include JSONAttributes
    # see attributes_to_pull_from_json for the order if creating yourself
    def initialize(args)
      if args.length == 1 then
        # assume the json object was passed
        setup_attributes(args[0])
      else
        # otherwise assume normal construction according to the order for the json attributes 
        self.class.json_attributes.each_with_index do |attribute, i|
          underscored = attribute.to_s.underscore
          raise ArgumentError("You must pass #{attribute} as argument #{i+1}") if self.class.json_attributes.length <= i 
          self.send("#{underscored}=", args[i])
        end
      end
    end

    def to_hash()
      ret_hash = {}
      self.class.json_attributes.each do |attrib|
        ret_hash[attrib] = self.send(attrib.to_s.underscore)
      end
      return ret_hash
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
myjohndeere-0.1.11 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.10 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.9 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.8 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.7 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.6 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.5 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.4 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.3 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.2 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.1 lib/myjohndeere/api_support_item.rb
myjohndeere-0.1.0 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.11 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.10 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.9 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.8 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.7 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.6 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.5 lib/myjohndeere/api_support_item.rb
myjohndeere-0.0.4 lib/myjohndeere/api_support_item.rb