Class: AsciiChem::Transform::MechanismBuilder

Inherits:
Object
  • Object
show all
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

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

#buildObject



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