Class: AsciiChem::Model::Reaction
- Defined in:
- lib/asciichem/model/reaction.rb
Overview
A chemical reaction: reactants, an arrow, and products. Conditions render above and below the arrow per IUPAC.
Defined Under Namespace
Classes: Conditions
Constant Summary collapse
- ARROWS =
{ forward: { ascii: "->", mathml_entity: "→" }, reverse: { ascii: "<-", mathml_entity: "←" }, equilibrium: { ascii: "<=>", mathml_entity: "⇌" }, resonance: { ascii: "<->", mathml_entity: "↔" } }.freeze
Instance Attribute Summary collapse
-
#arrow ⇒ Object
Returns the value of attribute arrow.
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#products ⇒ Object
Returns the value of attribute products.
-
#reactants ⇒ Object
Returns the value of attribute reactants.
Instance Method Summary collapse
- #arrow_ascii ⇒ Object
- #arrow_entity ⇒ Object
- #children ⇒ Object
-
#initialize(reactants:, products:, arrow: :forward, conditions: nil) ⇒ Reaction
constructor
A new instance of Reaction.
- #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(reactants:, products:, arrow: :forward, conditions: nil) ⇒ Reaction
Returns a new instance of Reaction.
19 20 21 22 23 24 |
# File 'lib/asciichem/model/reaction.rb', line 19 def initialize(reactants:, products:, arrow: :forward, conditions: nil) @reactants = reactants @products = products @arrow = arrow @conditions = conditions || Conditions.new end |
Instance Attribute Details
#arrow ⇒ Object
Returns the value of attribute arrow.
17 18 19 |
# File 'lib/asciichem/model/reaction.rb', line 17 def arrow @arrow end |
#conditions ⇒ Object
Returns the value of attribute conditions.
17 18 19 |
# File 'lib/asciichem/model/reaction.rb', line 17 def conditions @conditions end |
#products ⇒ Object
Returns the value of attribute products.
17 18 19 |
# File 'lib/asciichem/model/reaction.rb', line 17 def products @products end |
#reactants ⇒ Object
Returns the value of attribute reactants.
17 18 19 |
# File 'lib/asciichem/model/reaction.rb', line 17 def reactants @reactants end |
Instance Method Details
#arrow_ascii ⇒ Object
35 36 37 |
# File 'lib/asciichem/model/reaction.rb', line 35 def arrow_ascii ARROWS.fetch(arrow).fetch(:ascii) end |
#arrow_entity ⇒ Object
39 40 41 |
# File 'lib/asciichem/model/reaction.rb', line 39 def arrow_entity ARROWS.fetch(arrow).fetch(:mathml_entity) end |
#children ⇒ Object
31 32 33 |
# File 'lib/asciichem/model/reaction.rb', line 31 def children reactants + products end |
#to_s ⇒ Object
43 44 45 46 |
# File 'lib/asciichem/model/reaction.rb', line 43 def to_s "Reaction(#{reactants.map(&:to_s).join(' + ')} " \ "#{arrow_ascii} #{products.map(&:to_s).join(' + ')})" end |
#value_attributes ⇒ Object
26 27 28 29 |
# File 'lib/asciichem/model/reaction.rb', line 26 def value_attributes { reactants: reactants, products: products, arrow: arrow, conditions: conditions } end |