module ChemistryParadise::Shared
Constants
- ARRAY_TEST_THESE_MOLECULES
#¶ ↑
ARRAY_TEST_THESE_MOLECULES
¶ ↑Test these molecules. Default values.
#¶ ↑
Public Class Methods
convert_parens(i)
click to toggle source
#¶ ↑
ChemistryParadise::Shared.convert_parens
¶ ↑
This method will properly convert the () parens that can be found in a chemical formula.
For instance:
Al2(SO4)3
Is effectively the same such as:
Al2SO4SO4SO4
#¶ ↑
# File lib/chemistry_paradise/shared.rb, line 79 def self.convert_parens(i) if i.is_a? Array i.each {|entry| convert_parens(entry) } else if i.include? '(' n_parens = i.count('(') if n_parens > 1 # Ok, this may be a really complex formula, like: # Fe(OH)3 + H2SO4 -> Fe2(SO4)3 + H2O splitted = i.split(' ') splitted = splitted.map {|entry| convert_parens(entry) } # For now we remove some things. return splitted.join(' ') else regex = /\((.+)\)(\d)/ match = i.match(regex) i = i[0, i.index('(')] i << match[1] * match[2].to_i # Which group * n repetition end end return i end end
Public Instance Methods
convert_parens(i)
click to toggle source
#¶ ↑
convert_parens
¶ ↑
#¶ ↑
# File lib/chemistry_paradise/shared.rb, line 151 def convert_parens(i) ChemistryParadise::Shared.convert_parens(i) end
Also aliased as: parse
is_number?(i)
click to toggle source
periodic_table?()
click to toggle source
return_range_for_this_period(this_period = 1)
click to toggle source
#¶ ↑
return_range_for_this_period
¶ ↑
This method will tell us the legal range of elements for any given period.
The formula would be:
2+4n
For instance:
period 1 will return (1..2). period 2 will return (3..8).
#¶ ↑
# File lib/chemistry_paradise/shared.rb, line 129 def return_range_for_this_period(this_period = 1) case this_period when 1 (1..2) when 2 (3..10) when 3 (11..18) when 4 (19..36) when 5 (37..54) when 6 (55..86) when 7 (87..118) end end