Class: OpenGraphReader::Parser::Graph::Node Private

Inherits:
Struct
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/open_graph_reader/parser/graph.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A node in the graph.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



8
9
10
# File 'lib/open_graph_reader/parser/graph.rb', line 8

def content
  @content
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



8
9
10
# File 'lib/open_graph_reader/parser/graph.rb', line 8

def name
  @name
end

#parentNode?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The parent node.

Returns:



15
16
17
# File 'lib/open_graph_reader/parser/graph.rb', line 15

def parent
  @parent
end

Instance Method Details

#<<(node) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add children.

Parameters:



42
43
44
45
# File 'lib/open_graph_reader/parser/graph.rb', line 42

def << node
  node.parent = self
  children << node
end

#childrenObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Children of this node.



25
26
27
# File 'lib/open_graph_reader/parser/graph.rb', line 25

def children
  @children ||= []
end

#each {|Node| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterate over all children.

Yields:



32
33
34
35
36
37
# File 'lib/open_graph_reader/parser/graph.rb', line 32

def each(&block)
  children.each do |child|
    yield child
    child.each(&block)
  end
end

#empty?Bool

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Does this node have any content or non-empty children?

Returns:

  • (Bool)


20
21
22
# File 'lib/open_graph_reader/parser/graph.rb', line 20

def empty?
  content.nil? && (children.empty? || children.all?(&:empty?))
end

#fullnameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get node’s full name.

Returns:

  • (String)


64
65
66
67
# File 'lib/open_graph_reader/parser/graph.rb', line 64

def fullname
  @fullname ||= [namespace, name].compact.join(":")
  @fullname unless @fullname.empty?
end

#inspectObject Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



69
70
71
# File 'lib/open_graph_reader/parser/graph.rb', line 69

def inspect
  "#{super.chop} children=#{children.inspect}>"
end

#namespaceString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get node’s namespace.

Returns:

  • (String)


50
51
52
# File 'lib/open_graph_reader/parser/graph.rb', line 50

def namespace
  parent.fullname if parent
end

#pathArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get node’s namespace as array.

Returns:

  • (Array<String>)


57
58
59
# File 'lib/open_graph_reader/parser/graph.rb', line 57

def path
  @path ||= fullname.split(":")
end