Class: MyJohnDeere::APISupportItem
- Inherits:
-
Object
- Object
- MyJohnDeere::APISupportItem
- Includes:
- JSONAttributes
- Defined in:
- lib/myjohndeere/api_support_item.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(args) ⇒ APISupportItem
constructor
see attributes_to_pull_from_json for the order if creating yourself.
- #to_hash ⇒ Object
Methods included from JSONAttributes
Constructor Details
#initialize(args) ⇒ APISupportItem
see attributes_to_pull_from_json for the order if creating yourself
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/myjohndeere/api_support_item.rb', line 5 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 |
Instance Method Details
#to_hash ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/myjohndeere/api_support_item.rb', line 19 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 |