Class: A2z::Responses::BrowseNode
- 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
Constructor Details
#initialize ⇒ BrowseNode
Returns a new instance of BrowseNode.
6 7 8 9 10 |
# File 'lib/a2z/responses/browse_node.rb', line 6 def initialize @ancestors = [] @children = [] @root = false end |
Instance Attribute Details
#ancestors ⇒ Object
Returns the value of attribute ancestors.
4 5 6 |
# File 'lib/a2z/responses/browse_node.rb', line 4 def ancestors @ancestors end |
#children ⇒ Object
Returns the value of attribute children.
4 5 6 |
# File 'lib/a2z/responses/browse_node.rb', line 4 def children @children end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/a2z/responses/browse_node.rb', line 4 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/a2z/responses/browse_node.rb', line 4 def name @name end |
Class Method Details
.from_response(data) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/a2z/responses/browse_node.rb', line 24 def self.from_response(data) new.tap do |browse_node| 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 = data['Children']['BrowseNode'] children = [children] unless children.kind_of?(Array) browse_node.children = children.collect { |child| BrowseNode.from_response(child) } end if data['Ancestors'] && data['Ancestors']['BrowseNode'] ancestors = data['Ancestors']['BrowseNode'] ancestors = [ancestors] unless ancestors.kind_of?(Array) browse_node.ancestors = ancestors.collect { |ancestor| BrowseNode.from_response(ancestor) } end browse_node.freeze end end |
Instance Method Details
#root=(value) ⇒ Object
16 17 18 |
# File 'lib/a2z/responses/browse_node.rb', line 16 def root=(value) @root = !!value end |
#root? ⇒ Boolean
20 21 22 |
# File 'lib/a2z/responses/browse_node.rb', line 20 def root? @root end |