Class: NounProjectApi::BaseItem

Inherits:
Object
  • Object
show all
Defined in:
lib/noun-project-api/base_item.rb

Overview

A basis to Items returned by the noun project.

Direct Known Subclasses

Collection, Icon

Constant Summary collapse

ITEM_NAME =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

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_hashObject

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

#idObject



18
19
20
# File 'lib/noun-project-api/base_item.rb', line 18

def id
  original_hash["id"].to_i
end

#to_jsonObject



22
23
24
# File 'lib/noun-project-api/base_item.rb', line 22

def to_json
  JSON.dump(to_hash)
end