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.
-
#name ⇒ Object
Returns the value of attribute name.
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.
8 9 10 11 12 |
# File 'lib/a2z/responses/browse_node.rb', line 8 def initialize @ancestors = [] @children = [] @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 |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def name @name end |
Class Method Details
.from_response(data) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/a2z/responses/browse_node.rb', line 26 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 end browse_node.freeze end end |
Instance Method Details
#root=(value) ⇒ Object
18 19 20 |
# File 'lib/a2z/responses/browse_node.rb', line 18 def root=(value) @root = !!value end |
#root? ⇒ Boolean
22 23 24 |
# File 'lib/a2z/responses/browse_node.rb', line 22 def root? @root end |