Sha256: a39f9509b7c941a37c8b81833f6fc2d04eed6ccd74a3c1a261e6aa526ca00353
Contents?: true
Size: 1.28 KB
Versions: 2
Compression:
Stored size: 1.28 KB
Contents
module A2z module Responses class BrowseNode include Helpers attr_accessor :id, :name, :ancestors, :children def initialize @ancestors = [] @children = [] @root = false end def id=(value) @id = value.to_i end def root=(value) @root = !!value end def root? @root end 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
a2z-0.1.1 | lib/a2z/responses/browse_node.rb |
a2z-0.1.0 | lib/a2z/responses/browse_node.rb |