Class: AsciiChem::Transform::MechanismBuilder
- Inherits:
-
Object
- Object
- AsciiChem::Transform::MechanismBuilder
- Defined in:
- lib/asciichem/transform.rb
Overview
Builds a Mechanism from grammar captures. Each body line: key: value (step1: reaction, spectator: ion)
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(body_str) ⇒ MechanismBuilder
constructor
A new instance of MechanismBuilder.
Constructor Details
#initialize(body_str) ⇒ MechanismBuilder
Returns a new instance of MechanismBuilder.
410 411 412 |
# File 'lib/asciichem/transform.rb', line 410 def initialize(body_str) @body_str = strip_value(body_str) end |
Instance Method Details
#build ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/asciichem/transform.rb', line 414 def build steps = [] spectators = [] parse_entries(@body_str).each do |key, value| if key == 'spectator' spectators.concat(value.split(/\s+/).map(&:strip)) else steps << { label: key, reaction: value } end end Model::Mechanism.new(steps: steps, spectators: spectators) end |