Class: SelfSDK::Messages::Fact

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messaging) ⇒ Fact

Returns a new instance of Fact.

[View source]

10
11
12
# File 'lib/messages/fact.rb', line 10

def initialize(messaging)
  @messaging = messaging
end

Instance Attribute Details

#attestationsObject

Returns the value of attribute attestations.


8
9
10
# File 'lib/messages/fact.rb', line 8

def attestations
  @attestations
end

#expected_valueObject

Returns the value of attribute expected_value.


8
9
10
# File 'lib/messages/fact.rb', line 8

def expected_value
  @expected_value
end

#nameObject

Returns the value of attribute name.


8
9
10
# File 'lib/messages/fact.rb', line 8

def name
  @name
end

#operatorObject

Returns the value of attribute operator.


8
9
10
# File 'lib/messages/fact.rb', line 8

def operator
  @operator
end

#sourcesObject

Returns the value of attribute sources.


8
9
10
# File 'lib/messages/fact.rb', line 8

def sources
  @sources
end

Instance Method Details

#parse(fact) ⇒ Object

[View source]

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/messages/fact.rb', line 14

def parse(fact)
  @name = SelfSDK::fact_name(fact[:fact])

  @operator = ""
  @operator = SelfSDK::operator(fact[:operator]) if fact[:operator]

  @sources = []
  fact[:sources]&.each do |s|
    @sources << SelfSDK::source(s)
  end

  @expected_value = fact[:expected_value] || ""
  @attestations = []

  fact[:attestations]&.each do |a|
      attestation = SelfSDK::Messages::Attestation.new(@messaging)
      attestation.parse(fact[:fact].to_sym, a)
      @attestations.push(attestation)
    end
end

#to_hashObject

[View source]

41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/messages/fact.rb', line 41

def to_hash
  h = { fact: @name }
  unless @sources.nil?
    h[:sources] = @sources if @sources.length > 0
  end
  h[:operator] = @operator unless @operator.empty?
  unless @attestations.nil?
    h[:attestations] = @attestations if @attestations.length > 0
  end
  h[:expected_value] = @expected_value unless @expected_value.empty?
  h
end

#validate!(original) ⇒ Object

[View source]

35
36
37
38
39
# File 'lib/messages/fact.rb', line 35

def validate!(original)
  @attestations.each do |a|
    a.validate! original
  end
end