class ChemistryParadise::SplitMoleculeNames
Public Class Methods
Public Instance Methods
determine_total(i = @result)
click to toggle source
#¶ ↑
determine_total
¶ ↑
If the input is @result then it was already properly pre-sorted for us.
#¶ ↑
# File lib/chemistry_paradise/split_molecule_names.rb, line 117 def determine_total(i = @result) i.each {|entry| this_real_key = ignore_numbers(entry) if @total.has_key? this_real_key @total[this_real_key] = @total[this_real_key]+return_n_elements(entry) else # Else we must make a new key; the Laufindex kann aber 1-n sein. @total[this_real_key] = return_n_elements(entry) end } end
ignore_numbers(i)
click to toggle source
is_number?(i)
click to toggle source
reset()
click to toggle source
result?()
click to toggle source
#¶ ↑
result?¶ ↑
#¶ ↑
# File lib/chemistry_paradise/split_molecule_names.rb, line 43 def result? @result end
Also aliased as: result
return_n_elements(i)
click to toggle source
set_input(i)
click to toggle source
#¶ ↑
set_input
¶ ↑
#¶ ↑
# File lib/chemistry_paradise/split_molecule_names.rb, line 138 def set_input(i) if i i = convert_parens(i) if i.include? ')' if i.include? ' ' i.strip! if i.include? '+' # Ok, input here can be like: '2 Fe + 3 Cl2' i = i.gsub(/(\d)+ /,'\1') i = i.gsub(/ \+ /,'') end # ===================================================================== # # But it can also include internal ' ', which we will remove next. # ===================================================================== # i.delete!(' ') end end @input = i end
split(i = @input)
click to toggle source
#¶ ↑
split¶ ↑
This method will return an array with all the elements.
#¶ ↑
# File lib/chemistry_paradise/split_molecule_names.rb, line 63 def split(i = @input) array = [] _ = ''.dup if i i.chars.each_with_index {|token, index| if is_number? token # We found a number here. We simply append it then. _ << token # return the old data elsif token.downcase == token _ << token else # Not a number, must be a character. unless _.empty? array << _ _ = ''.dup end _ = token end array << _ if (index + 1) == i.size } @result = array determine_total return array end end