lib/eulim/chemistry/reaction.rb in eulim-0.0.12 vs lib/eulim/chemistry/reaction.rb in eulim-0.0.13

- old
+ new

@@ -3,20 +3,24 @@ # This class has functionality for reaction # Ex: check for balanced rxn, validity of a rxn class Reaction attr_accessor :equation, :is_valid, :is_balanced, :species - STATES = { '(s)' => 'solid', '(l)' => 'liquid', '(g)' => 'gaseous', '(aq)' => 'aqueous', "" => 'liquid' } + STATES = { + '(s)' => 'solid', '(l)' => 'liquid', + '(g)' => 'gaseous', '(aq)' => 'aqueous', + '' => 'liquid' + }.freeze def initialize(arg) @equation = arg @species = build_species @is_valid = valid_rxn? @is_balanced = balanced_rxn? end - # private + private def build_species r = {} result = {} r[:reactants], r[:products] = @equation.split('>>') @@ -32,10 +36,10 @@ def get_specie_info(specie) sc = get_stoichiometry specie st = get_state specie offset_sc = sc.zero? ? 0 : sc.to_s.length offset_st = st.empty? ? 0 : st.length - specie_str = specie[offset_sc..(specie.length - offset_st -1)] + specie_str = specie[offset_sc..(specie.length - offset_st - 1)] { specie_str => { compound: Compound.new(specie_str), stoichiometry: sc.zero? ? 1 : sc, state: STATES[st]