Class: A2z::Responses::BrowseNode
- Includes:
- Helpers
- Defined in:
- lib/a2z/responses/browse_node.rb
Instance Attribute Summary collapse
-
#ancestors ⇒ Object
Returns the value of attribute ancestors.
-
#children ⇒ Object
Returns the value of attribute children.
-
#id ⇒ Object
Returns the value of attribute id.
-
#most_gifted ⇒ Object
Returns the value of attribute most_gifted.
-
#most_wished_for ⇒ Object
Returns the value of attribute most_wished_for.
-
#name ⇒ Object
Returns the value of attribute name.
-
#new_releases ⇒ Object
Returns the value of attribute new_releases.
-
#top_sellers ⇒ Object
Returns the value of attribute top_sellers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ BrowseNode
constructor
A new instance of BrowseNode.
- #root=(value) ⇒ Object
- #root? ⇒ Boolean
Methods included from Helpers
Constructor Details
#initialize ⇒ BrowseNode
Returns a new instance of BrowseNode.
9 10 11 12 13 14 15 16 17 |
# File 'lib/a2z/responses/browse_node.rb', line 9 def initialize @ancestors = [] @children = [] @most_gifted = [] @most_wished_for = [] @new_releases = [] @top_sellers = [] @root = false end |
Instance Attribute Details
#ancestors ⇒ Object
Returns the value of attribute ancestors.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def ancestors @ancestors end |
#children ⇒ Object
Returns the value of attribute children.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def children @children end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def id @id end |
#most_gifted ⇒ Object
Returns the value of attribute most_gifted.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def most_gifted @most_gifted end |
#most_wished_for ⇒ Object
Returns the value of attribute most_wished_for.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def most_wished_for @most_wished_for end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def name @name end |
#new_releases ⇒ Object
Returns the value of attribute new_releases.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def new_releases @new_releases end |
#top_sellers ⇒ Object
Returns the value of attribute top_sellers.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def top_sellers @top_sellers end |
Class Method Details
.from_response(data) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/a2z/responses/browse_node.rb', line 31 def self.from_response(data) new.tap do |browse_node| if data browse_node.id = data['BrowseNodeId'] browse_node.name = data['Name'] browse_node.root = data['IsCategoryRoot'] == '1' rescue false if data['Children'] && data['Children']['BrowseNode'] children = array_wrap(data['Children']['BrowseNode']) browse_node.children = children.collect { |child| BrowseNode.from_response(child) } end if data['Ancestors'] && data['Ancestors']['BrowseNode'] ancestors = array_wrap(data['Ancestors']['BrowseNode']) browse_node.ancestors = ancestors.collect { |ancestor| BrowseNode.from_response(ancestor) } end if data['TopItemSet'] top_item_sets = array_wrap(data['TopItemSet']) top_item_sets.each do |top_item_set| top_items = array_wrap(top_item_set['TopItem']).collect { |top_item| TopItem.from_response(top_item) } case top_item_set['Type'] when 'MostGifted' then browse_node.most_gifted = top_items when 'MostWishedFor' then browse_node.most_wished_for = top_items when 'NewReleases' then browse_node.new_releases = top_items when 'TopSellers' then browse_node.top_sellers = top_items end end end end browse_node.freeze end end |
Instance Method Details
#root=(value) ⇒ Object
23 24 25 |
# File 'lib/a2z/responses/browse_node.rb', line 23 def root=(value) @root = !!value end |
#root? ⇒ Boolean
27 28 29 |
# File 'lib/a2z/responses/browse_node.rb', line 27 def root? @root end |