Class: AsciiChem::Model::EmbeddedMath

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

Overview

A run of mathematics embedded in chemistry. Wraps a Plurimath::Math::Formula so we never reinvent math typography.

Source spelling: backtick-delimited, e.g. `K_c = [P]/[R]`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

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

Constructor Details

#initialize(formula:, source: nil) ⇒ EmbeddedMath

Returns a new instance of EmbeddedMath.



12
13
14
15
# File 'lib/asciichem/model/embedded_math.rb', line 12

def initialize(formula:, source: nil)
  @formula = formula
  @source = source
end

Instance Attribute Details

#formulaObject

Returns the value of attribute formula.



10
11
12
# File 'lib/asciichem/model/embedded_math.rb', line 10

def formula
  @formula
end

#sourceObject

Returns the value of attribute source.



10
11
12
# File 'lib/asciichem/model/embedded_math.rb', line 10

def source
  @source
end

Instance Method Details

#to_sObject



21
22
23
# File 'lib/asciichem/model/embedded_math.rb', line 21

def to_s
  "EmbeddedMath(#{source || formula.inspect})"
end

#value_attributesObject



17
18
19
# File 'lib/asciichem/model/embedded_math.rb', line 17

def value_attributes
  { formula: formula, source: source }
end