Class: ChemistryParadise::EquationSolver
- Inherits:
-
Base
- Object
- Base
- ChemistryParadise::EquationSolver
show all
- Defined in:
- lib/chemistry_paradise/utility_scripts/equation_solver.rb
Overview
require ‘equation_solver’; EquationSolver.new
Constant Summary
collapse
- THIS_FORMULA =
'NH3HHH + O2 -> N2 + H2O'
- TOKEN_TO_SPLIT_AT =
'->'
Constants inherited
from Base
Base::FILE_MOLECULAR_FORMULA_OF_DIFFERENT_MOLECULES, Base::NAMESPACE
Constants included
from Shared
Shared::ARRAY_TEST_THESE_MOLECULES
Constants included
from Constants
Constants::ELECTRON_NEGATIVITY_CHART, Constants::FILE_ATOMGEWICHTE, Constants::FILE_ELECTRON_NEGATIVITY_CHART, Constants::FILE_PERIODIC_TABLE_OF_THE_ELEMENTS, Constants::N, Constants::PLANK_CONSTANT, Constants::PROPER_FILLORDER, Constants::SPEED_OF_LIGHT
Instance Method Summary
collapse
Methods inherited from Base
#be_quiet, #be_verbose?, #cd, #cliner, #commandline_arguments?, #do_use_the_english_language, #do_use_the_german_language, #do_we_use_english?, #esystem, #first_argument?, #gold, #grey, #initialize_the_internal_hash, #internal_hash?, #is_on_roebe?, #mediumpurple, #namespace?, #olivedrab, #opnn, #rev, #royalblue, #set_be_verbose, #set_commandline_arguments, #sfancy, #steelblue, #teal, #tomato, #use_which_language?, #yellow
Methods included from Shared
#convert_parens, #is_number?, #periodic_table?, periodic_table?, #return_range_for_this_period, #square
Methods included from Constants
#electron_negativity_chart?
Constructor Details
#initialize(i = nil, run_already = true) ⇒ EquationSolver
29
30
31
32
33
34
35
36
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 29
def initialize(
i = nil,
run_already = true
)
reset
set_input(i)
run if run_already
end
|
Instance Method Details
#are_both_sides_equal? ⇒ Boolean
#
are_both_sides_equal?
#
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 106
def are_both_sides_equal?
result = false
left = SplitMoleculeNames.new(left?.delete('+')).total?
right = SplitMoleculeNames.new(right?.delete('+')).total?
result = ( left == right )
return result
end
|
#ensure_that_the_token_is_correct ⇒ Object
#
ensure_that_the_token_is_correct
#
77
78
79
80
81
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 77
def ensure_that_the_token_is_correct
if @input.include? '=' @token_to_split_at = '='
end
end
|
#left? ⇒ Boolean
63
64
65
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 63
def left?
@left_hand_side
end
|
#reset ⇒ Object
41
42
43
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 41
def reset @token_to_split_at = TOKEN_TO_SPLIT_AT
end
|
#right? ⇒ Boolean
70
71
72
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 70
def right?
@right_hand_side
end
|
#run ⇒ Object
120
121
122
123
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 120
def run ensure_that_the_token_is_correct
split_into_components
end
|
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 48
def set_input(i = '')
i = i.first if i.is_a? Array
i = THIS_FORMULA if i.nil?
i = i.to_s.dup
i.strip!
i.tr!(' ','')
@input = i
end
|
#split_into_components ⇒ Object
#
split_into_components
#
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/chemistry_paradise/utility_scripts/equation_solver.rb', line 86
def split_into_components
@left_hand_side, @right_hand_side = @input.
split(@token_to_split_at).map(&:strip)
p SplitMoleculeNames.new left?
p SplitMoleculeNames.new right?
if are_both_sides_equal?
opn; e 'Both sides are now equal.'
else
opn; e 'Both sides are not equal.'
end
end
|