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 ⇒ Object
Constructor Details
#initialize(origin) ⇒ BaseItem
Returns a new instance of BaseItem.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/noun-project-api/base_item.rb', line 7 def initialize(origin) fail(NotImplementedError, "Must use a subclass") if self.class::ITEM_NAME.nil? origin = JSON.parse(origin) if origin.is_a? String origin = origin.delete( self.class::ITEM_NAME ) if origin.key? self.class::ITEM_NAME @original_hash = origin end |
Instance Attribute Details
#original_hash ⇒ Object
Returns the value of attribute original_hash.
4 5 6 |
# File 'lib/noun-project-api/base_item.rb', line 4 def original_hash @original_hash end |
Instance Method Details
#id ⇒ Object
18 19 20 |
# File 'lib/noun-project-api/base_item.rb', line 18 def id original_hash["id"].to_i end |
#to_json ⇒ Object
22 23 24 |
# File 'lib/noun-project-api/base_item.rb', line 22 def to_json JSON.dump(to_hash) end |