Class: Urbit::Fact::BaseFact

Inherits:
Object
  • Object
show all
Defined in:
lib/urbit/fact/base_fact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(channel:, event:) ⇒ BaseFact

Returns a new instance of BaseFact.



8
9
10
11
12
# File 'lib/urbit/fact/base_fact.rb', line 8

def initialize(channel:, event:)
  @channel = channel
  @data = event.data
  @type = event.type
end

Instance Attribute Details

#ackObject (readonly)

Returns the value of attribute ack.



6
7
8
# File 'lib/urbit/fact/base_fact.rb', line 6

def ack
  @ack
end

#channelObject (readonly)

Returns the value of attribute channel.



6
7
8
# File 'lib/urbit/fact/base_fact.rb', line 6

def channel
  @channel
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/urbit/fact/base_fact.rb', line 6

def data
  @data
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/urbit/fact/base_fact.rb', line 6

def type
  @type
end

Instance Method Details

#add_ack(ack:) ⇒ Object



14
15
16
# File 'lib/urbit/fact/base_fact.rb', line 14

def add_ack(ack:)
  @ack = :ack
end

#contentsObject



18
19
20
# File 'lib/urbit/fact/base_fact.rb', line 18

def contents
  JSON.parse(@data)
end

#create_parserObject



22
23
24
# File 'lib/urbit/fact/base_fact.rb', line 22

def create_parser
  nil
end

#for_this_ship?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/urbit/fact/base_fact.rb', line 26

def for_this_ship?
  self.ship == @channel.ship
end

#graph_update?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/urbit/fact/base_fact.rb', line 30

def graph_update?
  false
end

#is_acknowledged?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/urbit/fact/base_fact.rb', line 34

def is_acknowledged?
  !@ack.nil?
end

#raw_jsonObject



38
39
40
# File 'lib/urbit/fact/base_fact.rb', line 38

def raw_json
  nil
end

#shipObject



42
43
44
# File 'lib/urbit/fact/base_fact.rb', line 42

def ship
  @channel.ship
end

#to_hObject



46
47
48
49
50
51
52
# File 'lib/urbit/fact/base_fact.rb', line 46

def to_h
  {
    ship:            self.ship.to_h,
    acknowleged:     self.is_acknowledged?,
    is_graph_update: self.graph_update?
  }
end

#to_sObject



54
55
56
# File 'lib/urbit/fact/base_fact.rb', line 54

def to_s
  "a #{self.class.name}(#{self.to_h})"
end