Class: Chemicalml::Dictionary::Model
- Inherits:
-
Object
- Object
- Chemicalml::Dictionary::Model
- Defined in:
- lib/chemicalml/dictionary/model.rb
Overview
The canonical dictionary model: namespace, prefix, title,
description, and an ordered collection of Entry instances.
Plain Ruby — no XML, no YAML. Loading from YAML goes through
Loader; the wire (XML) shape is Chemicalml::Cml::Dictionary.
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #entry_ids ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(namespace:, prefix:, title:, description: nil, entries: []) ⇒ Model
constructor
A new instance of Model.
- #lookup(qualified_name) ⇒ Object
- #lookup!(qualified_name) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(namespace:, prefix:, title:, description: nil, entries: []) ⇒ Model
Returns a new instance of Model.
13 14 15 16 17 18 19 20 |
# File 'lib/chemicalml/dictionary/model.rb', line 13 def initialize(namespace:, prefix:, title:, description: nil, entries: []) @namespace = namespace @prefix = prefix @title = title @description = description @entries = entries.to_a freeze end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
11 12 13 |
# File 'lib/chemicalml/dictionary/model.rb', line 11 def description @description end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
11 12 13 |
# File 'lib/chemicalml/dictionary/model.rb', line 11 def entries @entries end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
11 12 13 |
# File 'lib/chemicalml/dictionary/model.rb', line 11 def namespace @namespace end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
11 12 13 |
# File 'lib/chemicalml/dictionary/model.rb', line 11 def prefix @prefix end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
11 12 13 |
# File 'lib/chemicalml/dictionary/model.rb', line 11 def title @title end |
Instance Method Details
#entry_ids ⇒ Object
34 35 36 |
# File 'lib/chemicalml/dictionary/model.rb', line 34 def entry_ids entries.map(&:id) end |
#eql?(other) ⇒ Boolean Also known as: ==
48 49 50 |
# File 'lib/chemicalml/dictionary/model.rb', line 48 def eql?(other) other.is_a?(Model) && namespace == other.namespace && to_h == other.to_h end |
#hash ⇒ Object
53 54 55 |
# File 'lib/chemicalml/dictionary/model.rb', line 53 def hash [namespace, to_h].hash end |
#lookup(qualified_name) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/chemicalml/dictionary/model.rb', line 22 def lookup(qualified_name) _, id = split_qname(qualified_name) return nil unless id entries.find { |e| e.id == id } end |
#lookup!(qualified_name) ⇒ Object
29 30 31 32 |
# File 'lib/chemicalml/dictionary/model.rb', line 29 def lookup!(qualified_name) lookup(qualified_name) || raise(KeyError, "no entry #{qualified_name.inspect} in #{namespace}") end |
#to_h ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/chemicalml/dictionary/model.rb', line 38 def to_h { namespace: namespace, prefix: prefix, title: title, description: description, entries: entries.map(&:to_h) } end |