Class: AsciiChem::Model::Formula

Inherits:
Node
  • Object
show all
Defined in:
lib/asciichem/model/formula.rb

Overview

Top-level container: the root of every AsciiChem parse.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#==, #accept, #diagnostic_label, #hash, short_name, #to_cml, #to_html, #to_latex, #to_mathml, #to_svg, #to_text

Constructor Details

#initialize(nodes: []) ⇒ Formula

Returns a new instance of Formula.



9
10
11
# File 'lib/asciichem/model/formula.rb', line 9

def initialize(nodes: [])
  @nodes = nodes
end

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes.



7
8
9
# File 'lib/asciichem/model/formula.rb', line 7

def nodes
  @nodes
end

Instance Method Details

#<<(node) ⇒ Object



13
14
15
16
# File 'lib/asciichem/model/formula.rb', line 13

def <<(node)
  nodes << node
  self
end

#childrenObject



22
23
24
# File 'lib/asciichem/model/formula.rb', line 22

def children
  nodes
end

#to_sObject



26
27
28
# File 'lib/asciichem/model/formula.rb', line 26

def to_s
  "Formula[#{nodes.map(&:to_s).join(', ')}]"
end

#value_attributesObject



18
19
20
# File 'lib/asciichem/model/formula.rb', line 18

def value_attributes
  { nodes: nodes }
end