Class: ChemistryParadise::InteractiveChemistryShell
- Inherits:
-
Base
- Object
- Base
- ChemistryParadise::InteractiveChemistryShell
show all
- Defined in:
- lib/chemistry_paradise/interactive_chemistry_shell.rb
Overview
ChemistryParadise::InteractiveChemistryShell
Constant Summary
collapse
- PROMPT =
'> '
- PERIODIC_TABLE =
nil
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
39
40
41
42
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 39
def initialize(run_already = true)
reset
run if run_already
end
|
Instance Method Details
#calculate(i) ⇒ Object
Also known as:
calc
#
calculate
To test this, do:
calc C3H5
#
82
83
84
85
86
87
88
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 82
def calculate(i)
if i.nil?
e 'Please provide proper input to this method now, for instance, `C12H12N2`:'
i = $stdin.gets.chomp
end
CalculateAtomicMass.new(i)
end
|
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 93
def
_ = @user_input arguments = nil if _.include? ' '
splitted = _.split(' ')
_ = splitted[0] arguments = splitted[1..-1]
end
case _ when 'quit','exit','q'
e 'Bye from the InteractiveChemistryShell.'
exit
when '4','show_electron_negativity_chart'
ChemistryParadise.show_electron_negativity_chart
when '3','periodic_table?','show_periodic_table','top','top?',
'periodic?','periodic','showperiodictable'
show_periodic_table
when /-?-?help/,'hel','he','h','?'
show_help
when '1','calc','calculate'
calculate(arguments)
when '2','show'
e 'Input your element symbol now:'
element_symbol = $stdin.gets.chomp
ShowElectronConfiguration.new(element_symbol)
when '' else
if @user_input.include?('g') and @user_input =~ /\d+/
splitted = @user_input.strip.split('g').map(&:strip)
atomic_mass = ChemistryParadise::CalculateAtomicMass[splitted.last].to_f
n_times = splitted.first.strip.to_i
mass = n_times / atomic_mass
e (mass.round(2)).to_s+' mol'
else
report_input(_)
show_help
end
end
end
|
#colourize_via_kde_konsole(i) ⇒ Object
#
colourize_via_kde_konsole
#
235
236
237
238
239
240
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 235
def colourize_via_kde_konsole(i)
if Object.const_defined? :Colours
i = ::Colours.lightgreen(i)
end
return i
end
|
150
151
152
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 150
def (i)
Colours.(i)
end
|
203
204
205
206
207
208
209
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 203
def fetch_user_input
if has_readline?
@user_input = Readline.readline('', true)
else
@user_input = $stdin.gets.chomp
end
end
|
#has_readline? ⇒ Boolean
196
197
198
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 196
def has_readline?
Object.const_defined? :Readline
end
|
64
65
66
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 64
def report_input(i)
ewarn 'Input was: `'+sfancy(i)+'`'
end
|
#reset ⇒ Object
47
48
49
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 47
def reset
@lpad = ' '
end
|
#run ⇒ Object
167
168
169
170
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 167
def run
show_welcome_message_and_help run_loop
end
|
#run_loop ⇒ Object
157
158
159
160
161
162
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 157
def run_loop
loop {
fetch_user_input
}
end
|
#show_help ⇒ Object
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 175
def show_help e 'Available options:'
e
array = [
'calculate the atomic mass',
'show the electron configuration of an Element',
'show the periodic table',
'show electron negativity chart'
]
array.each_with_index {|entry, index|
index += 1
@lpad+index.to_s+' # '+entry
}
end
|
#show_periodic_table ⇒ Object
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 214
def show_periodic_table
e inverted = PERIODIC_TABLE.invert
1.upto(7).each {|periode|
range = return_range_for_this_period(periode)
matches = inverted.select {|index_position, value|
range.include? index_position
}
ee colourize_via_kde_konsole(periode.to_s)+': ' matches.each_pair {|key, value|
ee simp(value)+' ('+key.to_s+') '
}; e
}
end
|
#show_welcome_message ⇒ Object
54
55
56
57
58
59
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 54
def show_welcome_message
e 'Welcome to the InteractiveChemistryShell.'
e 'Input "help" to get a list of options, otherwise'
e 'just type in your input now.'
print PROMPT
end
|
#show_welcome_message_and_help ⇒ Object
#
show_welcome_message_and_help
#
71
72
73
74
|
# File 'lib/chemistry_paradise/interactive_chemistry_shell.rb', line 71
def show_welcome_message_and_help
show_welcome_message
show_help
end
|