Class: Urbit::GraphParser
Direct Known Subclasses
Instance Method Summary collapse
-
#add_nodes ⇒ Object
Parses the embedded json and adds any found nodes to the graph.
-
#initialize(for_graph:, with_json:) ⇒ GraphParser
constructor
A new instance of GraphParser.
- #resource ⇒ Object
- #resource_hash ⇒ Object
Constructor Details
#initialize(for_graph:, with_json:) ⇒ GraphParser
Returns a new instance of GraphParser.
12 13 14 15 |
# File 'lib/urbit/parser.rb', line 12 def initialize(for_graph:, with_json:) super(with_json: with_json) @g = for_graph end |
Instance Method Details
#add_nodes ⇒ Object
Parses the embedded json and adds any found nodes to the graph. Answers an array of nodes.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/urbit/parser.rb', line 21 def add_nodes added_nodes = [] # Make sure we are adding to the correct graph... if (@g.resource == self.resource) self.nodes_hash.each do |k, v| added_nodes << (n = Urbit::Node.new(graph: @g, node_json: v)) @g.add_node(node: n) end end added_nodes end |
#resource ⇒ Object
33 34 35 |
# File 'lib/urbit/parser.rb', line 33 def resource "~#{self.resource_hash["ship"]}/#{self.resource_hash["name"]}" end |
#resource_hash ⇒ Object
37 38 39 |
# File 'lib/urbit/parser.rb', line 37 def resource_hash @j["resource"] end |