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
permalink #initialize(messaging) ⇒ Fact
Returns a new instance of Fact.
10 11 12 |
# File 'lib/messages/fact.rb', line 10 def initialize(messaging) @messaging = messaging end |
Instance Attribute Details
permalink #attestations ⇒ Object
Returns the value of attribute attestations.
8 9 10 |
# File 'lib/messages/fact.rb', line 8 def attestations @attestations end |
permalink #expected_value ⇒ Object
Returns the value of attribute expected_value.
8 9 10 |
# File 'lib/messages/fact.rb', line 8 def expected_value @expected_value end |
permalink #name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/messages/fact.rb', line 8 def name @name end |
permalink #operator ⇒ Object
Returns the value of attribute operator.
8 9 10 |
# File 'lib/messages/fact.rb', line 8 def operator @operator end |
permalink #sources ⇒ Object
Returns the value of attribute sources.
8 9 10 |
# File 'lib/messages/fact.rb', line 8 def sources @sources end |
Instance Method Details
permalink #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 |
permalink #to_hash ⇒ Object
[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 |
permalink #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 |