Class: OpenGraphReader::Parser::Graph Private
- Inherits:
-
Object
- Object
- OpenGraphReader::Parser::Graph
- 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 Graph to represent OpenGraph tags.
Defined Under Namespace
Classes: Node
Instance Attribute Summary collapse
-
#root ⇒ Node?
readonly
private
The initial node.
Instance Method Summary collapse
-
#each {|Node| ... } ⇒ Object
private
Iterate through all nodes that have a value.
-
#empty? ⇒ Bool
Does this graph have any nodes?.
-
#fetch(property, default = nil) { ... } ⇒ String, ...
private
Fetch first node’s value.
-
#find_by(property) ⇒ Node?
private
Fetch first node.
- #find_or_create_path(path) ⇒ Object private
-
#initialize ⇒ Graph
constructor
private
Create new graph.
-
#select_by(property) ⇒ Array<Node>
private
Fetch all nodes.
Constructor Details
#initialize ⇒ Graph
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.
Create new graph.
84 85 86 |
# File 'lib/open_graph_reader/parser/graph.rb', line 84 def initialize @root = Node.new end |
Instance Attribute Details
#root ⇒ Node? (readonly)
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 initial node.
75 76 77 |
# File 'lib/open_graph_reader/parser/graph.rb', line 75 def root @root end |
Instance Method Details
#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 through all nodes that have a value.
91 92 93 94 95 |
# File 'lib/open_graph_reader/parser/graph.rb', line 91 def each root.each do |child| yield child if child.content end end |
#empty? ⇒ Bool
Does this graph have any nodes?
81 |
# File 'lib/open_graph_reader/parser/graph.rb', line 81 def_delegators :root, :empty? |
#fetch(property, default = nil) { ... } ⇒ 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.
Fetch first node’s value.
103 104 105 106 107 108 |
# File 'lib/open_graph_reader/parser/graph.rb', line 103 def fetch property, default=nil node = find_by(property) return yield if node.nil? && block_given? return default if node.nil? node.content end |
#find_by(property) ⇒ Node?
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.
Fetch first node
114 115 116 117 |
# File 'lib/open_graph_reader/parser/graph.rb', line 114 def find_by property property = normalize_property property find {|node| node.fullname == property } end |
#find_or_create_path(path) ⇒ 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.
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/open_graph_reader/parser/graph.rb', line 128 def find_or_create_path path path.inject(root) {|node, name| child = node.children.reverse.find {|child| child.name == name } unless child child = Node.new name node << child end child } end |
#select_by(property) ⇒ Array<Node>
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.
Fetch all nodes
123 124 125 126 |
# File 'lib/open_graph_reader/parser/graph.rb', line 123 def select_by property property = normalize_property property select {|node| node.fullname == property } end |