Class: AsciiChem::Model::Group
- Defined in:
- lib/asciichem/model/group.rb
Overview
A parenthesised sub-formula with an outer multiplicity.
Instance Attribute Summary collapse
-
#bracket ⇒ Object
Returns the value of attribute bracket.
-
#multiplicity ⇒ Object
Returns the value of attribute multiplicity.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Instance Method Summary collapse
- #children ⇒ Object
- #close_char ⇒ Object
-
#initialize(nodes:, multiplicity: nil, bracket: :paren) ⇒ Group
constructor
A new instance of Group.
- #open_char ⇒ Object
- #to_s ⇒ Object
- #value_attributes ⇒ Object
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:, multiplicity: nil, bracket: :paren) ⇒ Group
Returns a new instance of Group.
9 10 11 12 13 |
# File 'lib/asciichem/model/group.rb', line 9 def initialize(nodes:, multiplicity: nil, bracket: :paren) @nodes = nodes @multiplicity = multiplicity @bracket = bracket end |
Instance Attribute Details
#bracket ⇒ Object
Returns the value of attribute bracket.
7 8 9 |
# File 'lib/asciichem/model/group.rb', line 7 def bracket @bracket end |
#multiplicity ⇒ Object
Returns the value of attribute multiplicity.
7 8 9 |
# File 'lib/asciichem/model/group.rb', line 7 def multiplicity @multiplicity end |
#nodes ⇒ Object
Returns the value of attribute nodes.
7 8 9 |
# File 'lib/asciichem/model/group.rb', line 7 def nodes @nodes end |
Instance Method Details
#children ⇒ Object
19 20 21 |
# File 'lib/asciichem/model/group.rb', line 19 def children nodes end |
#close_char ⇒ Object
34 35 36 |
# File 'lib/asciichem/model/group.rb', line 34 def close_char brackets.last end |
#open_char ⇒ Object
30 31 32 |
# File 'lib/asciichem/model/group.rb', line 30 def open_char brackets.first end |
#to_s ⇒ Object
23 24 25 26 27 28 |
# File 'lib/asciichem/model/group.rb', line 23 def to_s open, close = brackets inner = nodes.map(&:to_s).join(", ") suffix = multiplicity ? "_#{multiplicity}" : "" "Group#{open}#{inner}#{close}#{suffix}" end |
#value_attributes ⇒ Object
15 16 17 |
# File 'lib/asciichem/model/group.rb', line 15 def value_attributes { nodes: nodes, multiplicity: multiplicity, bracket: bracket } end |