Class: SelfSDK::Messages::Fact
- Inherits:
-
Object
- Object
- SelfSDK::Messages::Fact
- Defined in:
- lib/messages/fact.rb
Instance Attribute Summary collapse
-
#attestations ⇒ Object
Returns the value of attribute attestations.
-
#expected_value ⇒ Object
Returns the value of attribute expected_value.
-
#name ⇒ Object
Returns the value of attribute name.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#sources ⇒ Object
Returns the value of attribute sources.
Instance Method Summary collapse
-
#initialize(messaging) ⇒ Fact
constructor
A new instance of Fact.
- #parse(fact) ⇒ Object
- #to_hash ⇒ Object
- #validate!(original) ⇒ Object
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
#attestations ⇒ Object
Returns the value of attribute attestations.
10 11 12 |
# File 'lib/messages/fact.rb', line 10 def attestations @attestations end |
#expected_value ⇒ Object
Returns the value of attribute expected_value.
10 11 12 |
# File 'lib/messages/fact.rb', line 10 def expected_value @expected_value end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/messages/fact.rb', line 10 def name @name end |
#operator ⇒ Object
Returns the value of attribute operator.
10 11 12 |
# File 'lib/messages/fact.rb', line 10 def operator @operator end |
#sources ⇒ Object
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) unless attestation.value.nil? end end |
#to_hash ⇒ Object
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 |