Class: Rapa::BrowseNode

Inherits:
Object
  • Object
show all
Defined in:
lib/rapa/browse_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ BrowseNode

Returns a new instance of BrowseNode.

Parameters:

  • source (Hash)


7
8
9
# File 'lib/rapa/browse_node.rb', line 7

def initialize(source)
  @source = source
end

Instance Attribute Details

#sourceHash (readonly)

Returns:

  • (Hash)


4
5
6
# File 'lib/rapa/browse_node.rb', line 4

def source
  @source
end

Instance Method Details

#ancestorsArray<Rapa::BrowseNode>

Returns:



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

#childrenArray<Rapa::BrowseNode>?

Returns:



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

#idInteger

Returns:

  • (Integer)


34
35
36
# File 'lib/rapa/browse_node.rb', line 34

def id
  source["BrowseNodeId"].to_i
end

#nameString

Returns:

  • (String)


39
40
41
# File 'lib/rapa/browse_node.rb', line 39

def name
  source["Name"]
end

#parentRapa::BrowseNode?

Returns:



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_ancestorsArray<Rapa::BrowseNode>

Returns:



51
52
53
# File 'lib/rapa/browse_node.rb', line 51

def self_or_ancestors
  [self] + ancestors
end

#titleString

Returns:

  • (String)


56
57
58
# File 'lib/rapa/browse_node.rb', line 56

def title
  source["Title"]
end