Class: Necropsy::ValueFact
- Inherits:
-
Data
- Object
- Data
- Necropsy::ValueFact
- Defined in:
- lib/necropsy/models.rb
Instance Attribute Summary collapse
-
#exact ⇒ Object
readonly
Returns the value of attribute exact.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#nilable ⇒ Object
readonly
Returns the value of attribute nilable.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
- .from_h(attributes) ⇒ Object
- .instance_types(types, origin: :direct_constructor, nilable: false) ⇒ Object
- .unknown(origin = :unsupported) ⇒ Object
Instance Method Summary collapse
- #exact_instance_types? ⇒ Boolean
-
#initialize(kind:, values: [], exact: true, nilable: false, origin: nil, summary: nil) ⇒ ValueFact
constructor
A new instance of ValueFact.
- #to_h ⇒ Object
Constructor Details
#initialize(kind:, values: [], exact: true, nilable: false, origin: nil, summary: nil) ⇒ ValueFact
Returns a new instance of ValueFact.
722 723 724 725 726 727 728 729 730 731 |
# File 'lib/necropsy/models.rb', line 722 def initialize(kind:, values: [], exact: true, nilable: false, origin: nil, summary: nil) kind = kind.to_sym raise ArgumentError, "invalid value fact kind: #{kind.inspect}" unless VALUE_FACT_KINDS.include?(kind) values = Array(values).map(&:to_s).uniq.sort.freeze exact = (exact == true) nilable = (nilable == true) origin = origin&.to_s super end |
Instance Attribute Details
#exact ⇒ Object (readonly)
Returns the value of attribute exact
721 722 723 |
# File 'lib/necropsy/models.rb', line 721 def exact @exact end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
721 722 723 |
# File 'lib/necropsy/models.rb', line 721 def kind @kind end |
#nilable ⇒ Object (readonly)
Returns the value of attribute nilable
721 722 723 |
# File 'lib/necropsy/models.rb', line 721 def nilable @nilable end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin
721 722 723 |
# File 'lib/necropsy/models.rb', line 721 def origin @origin end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary
721 722 723 |
# File 'lib/necropsy/models.rb', line 721 def summary @summary end |
#values ⇒ Object (readonly)
Returns the value of attribute values
721 722 723 |
# File 'lib/necropsy/models.rb', line 721 def values @values end |
Class Method Details
.from_h(attributes) ⇒ Object
741 742 743 744 745 746 747 748 749 750 751 |
# File 'lib/necropsy/models.rb', line 741 def self.from_h(attributes) data = attributes.transform_keys(&:to_s) new( kind: data.fetch('kind'), values: data.fetch('values', []), exact: data.fetch('exact', false), nilable: data.fetch('nilable', false), origin: data['origin'], summary: data['summary'] ) end |
.instance_types(types, origin: :direct_constructor, nilable: false) ⇒ Object
733 734 735 |
# File 'lib/necropsy/models.rb', line 733 def self.instance_types(types, origin: :direct_constructor, nilable: false) new(kind: :instance_types, values: types, exact: true, nilable: nilable, origin: origin) end |
.unknown(origin = :unsupported) ⇒ Object
737 738 739 |
# File 'lib/necropsy/models.rb', line 737 def self.unknown(origin = :unsupported) new(kind: :unknown, exact: false, origin: origin) end |
Instance Method Details
#exact_instance_types? ⇒ Boolean
753 754 755 |
# File 'lib/necropsy/models.rb', line 753 def exact_instance_types? kind == :instance_types && exact && !values.empty? end |
#to_h ⇒ Object
757 758 759 760 761 762 763 764 765 766 |
# File 'lib/necropsy/models.rb', line 757 def to_h { 'kind' => kind.to_s, 'values' => values, 'exact' => exact, 'nilable' => nilable, 'origin' => origin, 'summary' => summary } end |