Class: Chemicalml::Model::Node
- Inherits:
-
Object
- Object
- Chemicalml::Model::Node
show all
- Defined in:
- lib/chemicalml/model/node.rb
Overview
Base class for every canonical model node. Mirrors the contract
of AsciiChem::Model::Node so visitors written against one
model work against the other without modification.
Direct Known Subclasses
Array, Atom, Bond, Document, Formula, Identifier, Label, Matrix, Metadata, MetadataList, Module, Molecule, Name, Parameter, ParameterList, Product, ProductList, Property, PropertyList, Reactant, ReactantList, Reaction, ReactionList, Scalar, Substance
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.short_name ⇒ Object
35
36
37
38
39
40
41
42
|
# File 'lib/chemicalml/model/node.rb', line 35
def self.short_name
@short_name ||= begin
snake = name.split("::").last
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
snake.downcase
end
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
18
19
20
|
# File 'lib/chemicalml/model/node.rb', line 18
def ==(other)
other.is_a?(self.class) && value_attributes == other.value_attributes
end
|
#accept(visitor) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/chemicalml/model/node.rb', line 9
def accept(visitor)
visitor.public_send(:"visit_#{self.class.short_name}", self)
rescue NoMethodError => e
raise unless e.name == :"visit_#{self.class.short_name}"
raise NotImplementedError,
"#{visitor.class} does not implement visit_#{self.class.short_name}"
end
|
#children ⇒ Object
27
28
29
|
# File 'lib/chemicalml/model/node.rb', line 27
def children
[]
end
|
#hash ⇒ Object
23
24
25
|
# File 'lib/chemicalml/model/node.rb', line 23
def hash
[self.class, value_attributes].hash
end
|
#value_attributes ⇒ Object
31
32
33
|
# File 'lib/chemicalml/model/node.rb', line 31
def value_attributes
{}
end
|