class Urbit::Fact
Attributes
ack[R]
Public Class Methods
new(channel:, event:)
click to toggle source
# File lib/urbit/fact.rb, line 9 def initialize(channel:, event:) @channel = channel @data = event.data @type = event.type # Attach this new fact as a node to its Graph. if self.graph_update? puts self.add_nodes_json Urbit::AddNodesParser.new(for_graph: (self.ship.graph(resource: self.resource)), with_json: self.add_nodes_json).add_nodes end end
Public Instance Methods
add_ack(ack:)
click to toggle source
# File lib/urbit/fact.rb, line 21 def add_ack(ack:) @ack = :ack end
add_nodes_json()
click to toggle source
# File lib/urbit/fact.rb, line 25 def add_nodes_json return nil unless self.graph_update? self.contents["json"]["graph-update"]["add-nodes"] end
contents()
click to toggle source
# File lib/urbit/fact.rb, line 30 def contents JSON.parse(@data) end
graph_update?()
click to toggle source
# File lib/urbit/fact.rb, line 34 def graph_update? !self.contents["json"].nil? && !self.contents["json"]["graph-update"].nil? end
is_acknowledged?()
click to toggle source
# File lib/urbit/fact.rb, line 38 def is_acknowledged? !@ack.nil? end
resource()
click to toggle source
# File lib/urbit/fact.rb, line 42 def resource return nil unless self.graph_update? r = self.contents["json"]["graph-update"]["add-nodes"]["resource"] "~#{r["ship"]}/#{r["name"]}" end
ship()
click to toggle source
# File lib/urbit/fact.rb, line 48 def ship @channel.ship end
to_h()
click to toggle source
# File lib/urbit/fact.rb, line 52 def to_h { ship: self.ship.to_h, resource: self.resource, acknowleged: self.is_acknowledged?, is_graph_update: self.graph_update? # contents: self.contents } end
to_s()
click to toggle source
# File lib/urbit/fact.rb, line 62 def to_s "a Fact(#{self.to_h})" end