Class: Necropsy::TypeFact
- Inherits:
-
Data
- Object
- Data
- Necropsy::TypeFact
- Defined in:
- lib/necropsy/type_facts.rb
Instance Attribute Summary collapse
-
#complete ⇒ Object
readonly
Returns the value of attribute complete.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#trust ⇒ Object
readonly
Returns the value of attribute trust.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#initialize(subject:, types:, source:, trust: :hint, complete: false) ⇒ TypeFact
constructor
A new instance of TypeFact.
- #safe_for_resolution? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(subject:, types:, source:, trust: :hint, complete: false) ⇒ TypeFact
Returns a new instance of TypeFact.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/necropsy/type_facts.rb', line 7 def initialize(subject:, types:, source:, trust: :hint, complete: false) subject = subject.to_s raise ArgumentError, 'type fact subject must not be empty' if subject.empty? types = Array(types).map(&:to_s).reject(&:empty?).uniq.sort.freeze raise ArgumentError, 'type fact requires at least one type' if types.empty? trust = trust.to_sym raise ArgumentError, "invalid type fact trust: #{trust.inspect}" unless TYPE_FACT_TRUST_LEVELS.include?(trust) source = source.to_s raise ArgumentError, 'type fact source must not be empty' if source.empty? super(subject: subject.freeze, types: types, trust: trust, source: source.freeze, complete: complete == true) end |
Instance Attribute Details
#complete ⇒ Object (readonly)
Returns the value of attribute complete
6 7 8 |
# File 'lib/necropsy/type_facts.rb', line 6 def complete @complete end |
#source ⇒ Object (readonly)
Returns the value of attribute source
6 7 8 |
# File 'lib/necropsy/type_facts.rb', line 6 def source @source end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject
6 7 8 |
# File 'lib/necropsy/type_facts.rb', line 6 def subject @subject end |
#trust ⇒ Object (readonly)
Returns the value of attribute trust
6 7 8 |
# File 'lib/necropsy/type_facts.rb', line 6 def trust @trust end |
#types ⇒ Object (readonly)
Returns the value of attribute types
6 7 8 |
# File 'lib/necropsy/type_facts.rb', line 6 def types @types end |
Instance Method Details
#safe_for_resolution? ⇒ Boolean
23 24 25 |
# File 'lib/necropsy/type_facts.rb', line 23 def safe_for_resolution? trust == :authoritative && complete end |
#to_h ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/necropsy/type_facts.rb', line 27 def to_h { 'subject' => subject, 'types' => types, 'trust' => trust.to_s, 'source' => source, 'complete' => complete } end |