Class: NounProjectApi::BaseItem
- Inherits:
-
Object
- Object
- NounProjectApi::BaseItem
- Defined in:
- lib/noun_project_api/base_item.rb
Overview
A basis to Items returned by the noun project.
Direct Known Subclasses
Constant Summary collapse
- ITEM_NAME =
nil
Instance Attribute Summary collapse
-
#original_hash ⇒ Object
Returns the value of attribute original_hash.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(origin) ⇒ BaseItem
constructor
A new instance of BaseItem.
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(origin) ⇒ BaseItem
Returns a new instance of BaseItem.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/noun_project_api/base_item.rb', line 10 def initialize(origin) raise NotImplementedError, "Must use a subclass" if self.class::ITEM_NAME.nil? origin = JSON.parse(origin, symbolize_names: true) if origin.is_a? String if origin.key? self.class::ITEM_NAME origin = origin.delete( self.class::ITEM_NAME ) end @original_hash = origin end |
Instance Attribute Details
#original_hash ⇒ Object
Returns the value of attribute original_hash.
6 7 8 |
# File 'lib/noun_project_api/base_item.rb', line 6 def original_hash @original_hash end |
Instance Method Details
#id ⇒ Object
23 24 25 |
# File 'lib/noun_project_api/base_item.rb', line 23 def id original_hash[:id].to_i end |
#to_json(*_args) ⇒ Object
27 28 29 |
# File 'lib/noun_project_api/base_item.rb', line 27 def to_json(*_args) JSON.dump(to_hash) end |