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.



12
13
14
# File 'lib/messages/fact.rb', line 12

def initialize(messaging)
  @messaging = messaging
end

Instance Attribute Details

#attestationsObject

Returns the value of attribute attestations.



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

def attestations
  @attestations
end

#expected_valueObject

Returns the value of attribute expected_value.



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

def expected_value
  @expected_value
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#operatorObject

Returns the value of attribute operator.



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

def operator
  @operator
end

#sourcesObject

Returns the value of attribute sources.



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

def sources
  @sources
end

Instance Method Details

#parse(fact) ⇒ Object



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

def parse(fact)
  @name = @messaging.source.normalize_fact_name fact[:fact]
  @operator = @messaging.source.normalize_operator!(fact[:operator])
  @sources = []
  fact[:sources]&.each do |s|
    @sources << s.to_s
  end
  @issuers = []
  fact[:issuers]&.each do |i|
    @issuers << i.to_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



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/messages/fact.rb', line 44

def to_hash
  h = { fact: @name }
  h[:issuers] = @issuers if @issuers.length > 0
  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



38
39
40
41
42
# File 'lib/messages/fact.rb', line 38

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