class Urbit::Parser

Public Class Methods

new(for_graph:, with_json:) click to toggle source
# File lib/urbit/parser.rb, line 6
def initialize(for_graph:, with_json:)
  @g = for_graph
  @j = with_json
end

Public Instance Methods

add_nodes() click to toggle source

Parses the embedded json and adds any found nodes to the graph. Answers an array of nodes.

# File lib/urbit/parser.rb, line 15
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() click to toggle source
# File lib/urbit/parser.rb, line 27
def resource
  "~#{self.resource_hash["ship"]}/#{self.resource_hash["name"]}"
end
resource_hash() click to toggle source
# File lib/urbit/parser.rb, line 31
def resource_hash
  @j["resource"]
end