class Rapa::BrowseNode

Attributes

source[R]

@return [Hash]

Public Class Methods

new(source) click to toggle source

@param source [Hash]

# File lib/rapa/browse_node.rb, line 7
def initialize(source)
  @source = source
end

Public Instance Methods

ancestors() click to toggle source

@return [Array<Rapa::BrowseNode>]

# 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() click to toggle source

@return [Array<Rapa::BrowseNode>, nil]

# 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() click to toggle source

@return [Integer]

# File lib/rapa/browse_node.rb, line 34
def id
  source["BrowseNodeId"].to_i
end
name() click to toggle source

@return [String]

# File lib/rapa/browse_node.rb, line 39
def name
  source["Name"]
end
parent() click to toggle source

@return [Rapa::BrowseNode, nil]

# 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() click to toggle source

@return [Array<Rapa::BrowseNode>]

# File lib/rapa/browse_node.rb, line 51
def self_or_ancestors
  [self] + ancestors
end
title() click to toggle source

@return [String]

# File lib/rapa/browse_node.rb, line 56
def title
  source["Title"]
end