Class: Chemicalml::Dictionary::Entry
- Inherits:
-
Object
- Object
- Chemicalml::Dictionary::Entry
- Defined in:
- lib/chemicalml/dictionary/entry.rb
Overview
One dictionary entry. Plain Ruby value object — format-agnostic.
The YAML shape mirrors the structure documented in
TODO.cml-full/05-dictionary-layer.md.
Constant Summary collapse
- ID_PATTERN =
/\A[A-Za-z][A-Za-z0-9._-]*\z/.freeze
Instance Attribute Summary collapse
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#enum ⇒ Object
readonly
Returns the value of attribute enum.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#source_code ⇒ Object
readonly
Returns the value of attribute source_code.
-
#term ⇒ Object
readonly
Returns the value of attribute term.
-
#unit_type ⇒ Object
readonly
Returns the value of attribute unit_type.
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(id:, term:, definition:, description: nil, data_type: nil, unit_type: nil, units: nil, enum: nil, links: [], source_code: nil) ⇒ Entry
constructor
A new instance of Entry.
- #to_h ⇒ Object
Constructor Details
#initialize(id:, term:, definition:, description: nil, data_type: nil, unit_type: nil, units: nil, enum: nil, links: [], source_code: nil) ⇒ Entry
Returns a new instance of Entry.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chemicalml/dictionary/entry.rb', line 15 def initialize(id:, term:, definition:, description: nil, data_type: nil, unit_type: nil, units: nil, enum: nil, links: [], source_code: nil) raise ArgumentError, "invalid entry id: #{id.inspect}" unless id.to_s.match?(ID_PATTERN) @id = id.to_s @term = term @definition = definition @description = description @data_type = data_type @unit_type = unit_type @units = units @enum = enum @links = links.to_a @source_code = source_code freeze end |
Instance Attribute Details
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def data_type @data_type end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def definition @definition end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def description @description end |
#enum ⇒ Object (readonly)
Returns the value of attribute enum.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def enum @enum end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def id @id end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def links @links end |
#source_code ⇒ Object (readonly)
Returns the value of attribute source_code.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def source_code @source_code end |
#term ⇒ Object (readonly)
Returns the value of attribute term.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def term @term end |
#unit_type ⇒ Object (readonly)
Returns the value of attribute unit_type.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def unit_type @unit_type end |
#units ⇒ Object (readonly)
Returns the value of attribute units.
11 12 13 |
# File 'lib/chemicalml/dictionary/entry.rb', line 11 def units @units end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
49 50 51 |
# File 'lib/chemicalml/dictionary/entry.rb', line 49 def eql?(other) other.is_a?(Entry) && id == other.id && to_h == other.to_h end |
#hash ⇒ Object
54 55 56 |
# File 'lib/chemicalml/dictionary/entry.rb', line 54 def hash [id, to_h].hash end |
#to_h ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/chemicalml/dictionary/entry.rb', line 33 def to_h h = { id: id, term: term, definition: definition } h[:description] = description if description h[:data_type] = data_type if data_type h[:unit_type] = unit_type if unit_type h[:units] = units if units h[:enum] = enum.to_h if enum h[:links] = links.map(&:to_h) unless links.empty? h[:source_code] = source_code if source_code h end |