Class: Rapa::BrowseNode
- Inherits:
-
Object
- Object
- Rapa::BrowseNode
- Defined in:
- lib/rapa/browse_node.rb
Instance Attribute Summary collapse
- #source ⇒ Hash readonly
Instance Method Summary collapse
- #ancestors ⇒ Array<Rapa::BrowseNode>
- #children ⇒ Array<Rapa::BrowseNode>?
- #id ⇒ Integer
-
#initialize(source) ⇒ BrowseNode
constructor
A new instance of BrowseNode.
- #name ⇒ String
- #parent ⇒ Rapa::BrowseNode?
- #self_or_ancestors ⇒ Array<Rapa::BrowseNode>
- #title ⇒ String
Constructor Details
#initialize(source) ⇒ BrowseNode
Returns a new instance of BrowseNode.
7 8 9 |
# File 'lib/rapa/browse_node.rb', line 7 def initialize(source) @source = source end |
Instance Attribute Details
#source ⇒ Hash (readonly)
4 5 6 |
# File 'lib/rapa/browse_node.rb', line 4 def source @source end |
Instance Method Details
#ancestors ⇒ Array<Rapa::BrowseNode>
12 13 14 15 16 17 18 19 20 |
# File 'lib/rapa/browse_node.rb', line 12 def ancestors array = [] current = self while parent = current.parent do array << parent current = parent end array end |
#children ⇒ Array<Rapa::BrowseNode>?
23 24 25 26 27 28 29 30 31 |
# File 'lib/rapa/browse_node.rb', line 23 def children if child_sources = source.dig("Children", "BrowseNode") child_sources.map do |child_source| ::Rapa::BrowseNode.new(child_source) end else [] end end |
#id ⇒ Integer
34 35 36 |
# File 'lib/rapa/browse_node.rb', line 34 def id source["BrowseNodeId"].to_i end |
#name ⇒ String
39 40 41 |
# File 'lib/rapa/browse_node.rb', line 39 def name source["Name"] end |
#parent ⇒ Rapa::BrowseNode?
44 45 46 47 48 |
# File 'lib/rapa/browse_node.rb', line 44 def parent if parent_source = source.dig("Ancestors", "BrowseNode") ::Rapa::BrowseNode.new(parent_source) end end |
#self_or_ancestors ⇒ Array<Rapa::BrowseNode>
51 52 53 |
# File 'lib/rapa/browse_node.rb', line 51 def self_or_ancestors [self] + ancestors end |
#title ⇒ String
56 57 58 |
# File 'lib/rapa/browse_node.rb', line 56 def title source["Title"] end |