chemistry_paradise 1.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of chemistry_paradise might be problematic. Click here for more details.

Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +222 -0
  3. data/bin/chemistry_paradise +7 -0
  4. data/chemistry_paradise.gemspec +45 -0
  5. data/doc/BUGS.md +16 -0
  6. data/doc/README.gen +205 -0
  7. data/doc/TODO.md +13 -0
  8. data/lib/chemistry_paradise.rb +6 -0
  9. data/lib/chemistry_paradise/base/base.rb +101 -0
  10. data/lib/chemistry_paradise/base/colours.rb +65 -0
  11. data/lib/chemistry_paradise/calculate_atomic_mass.rb +487 -0
  12. data/lib/chemistry_paradise/combustion_analysis.rb +181 -0
  13. data/lib/chemistry_paradise/commandline/help.rb +35 -0
  14. data/lib/chemistry_paradise/commandline/menu.rb +80 -0
  15. data/lib/chemistry_paradise/commandline/parse_commandline.rb +94 -0
  16. data/lib/chemistry_paradise/constants/constants.rb +52 -0
  17. data/lib/chemistry_paradise/constants/file_constants.rb +27 -0
  18. data/lib/chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb +157 -0
  19. data/lib/chemistry_paradise/converters/celsius_to_fahrenheit.rb +134 -0
  20. data/lib/chemistry_paradise/converters/fahrenheit_to_celsius.rb +122 -0
  21. data/lib/chemistry_paradise/converters/shared.rb +15 -0
  22. data/lib/chemistry_paradise/electron_negativity_chart.rb +78 -0
  23. data/lib/chemistry_paradise/equalize_chemical_formula.rb +82 -0
  24. data/lib/chemistry_paradise/equation_solver.rb +130 -0
  25. data/lib/chemistry_paradise/interactive_chemistry_shell.rb +241 -0
  26. data/lib/chemistry_paradise/orbitals.rb +65 -0
  27. data/lib/chemistry_paradise/project/project_base_directory.rb +24 -0
  28. data/lib/chemistry_paradise/requires/common_external_requires.rb +17 -0
  29. data/lib/chemistry_paradise/shared.rb +162 -0
  30. data/lib/chemistry_paradise/show_electron_configuration.rb +243 -0
  31. data/lib/chemistry_paradise/show_electron_negativity_of_this_element.rb +101 -0
  32. data/lib/chemistry_paradise/show_element.rb +141 -0
  33. data/lib/chemistry_paradise/split_molecule_names.rb +185 -0
  34. data/lib/chemistry_paradise/toplevel_methods/atomgewichte.rb +31 -0
  35. data/lib/chemistry_paradise/toplevel_methods/display_where_the_molmasses_are_kept.rb +24 -0
  36. data/lib/chemistry_paradise/toplevel_methods/e.rb +16 -0
  37. data/lib/chemistry_paradise/toplevel_methods/kelvin.rb +34 -0
  38. data/lib/chemistry_paradise/toplevel_methods/language.rb +50 -0
  39. data/lib/chemistry_paradise/toplevel_methods/periodic_table.rb +16 -0
  40. data/lib/chemistry_paradise/toplevel_methods/remove_this_molecule_from.rb +63 -0
  41. data/lib/chemistry_paradise/toplevel_methods/show_electron_negativity_chart.rb +26 -0
  42. data/lib/chemistry_paradise/verbose_chemical_calculation.rb +21 -0
  43. data/lib/chemistry_paradise/version/version.rb +19 -0
  44. data/lib/chemistry_paradise/yaml/atomgewichte.yml +109 -0
  45. data/lib/chemistry_paradise/yaml/electron_negativity_chart.yml +109 -0
  46. data/lib/chemistry_paradise/yaml/molecular_formula_of_different_molecules.yml +12 -0
  47. data/test/testing_chemistry_paradise.rb +49 -0
  48. metadata +138 -0
data/doc/TODO.md ADDED
@@ -0,0 +1,13 @@
1
+ - 1.32 * (10 ** -3) # => 0.00132
2
+ x = 0.00132 # => 0.00132
3
+ log x # => -2.87942606879415
4
+ -(log x)
5
+ # => 2.87942606879415
6
+
7
+ ^^^ chemparadise sollte diese steps angeben.
8
+
9
+
10
+ - we should ahve an interactive periodensystem
11
+ that tells us which periods we have. not sure
12
+ if this shall be integrated into the shell
13
+ or be separate.
@@ -0,0 +1,6 @@
1
+ require 'chemistry_paradise/calculate_atomic_mass.rb'
2
+ require 'chemistry_paradise/show_electron_configuration.rb'
3
+ require 'chemistry_paradise/equalize_chemical_formula.rb'
4
+ require 'chemistry_paradise/commandline/parse_commandline.rb'
5
+ require 'chemistry_paradise/toplevel_methods/atomgewichte.rb'
6
+ require 'chemistry_paradise/toplevel_methods/remove_this_molecule_from.rb'
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'chemistry_paradise/base/base.rb'; < ::ChemistryParadise::Base
6
+ # =========================================================================== #
7
+ require 'chemistry_paradise/toplevel_methods/language.rb'
8
+ require 'chemistry_paradise/shared.rb'
9
+ require 'chemistry_paradise/constants/german_names_of_elements_to_element_symbol.rb'
10
+ require 'chemistry_paradise/base/colours.rb'
11
+
12
+ module ChemistryParadise
13
+
14
+ class Base # === ChemistryParadise::Base
15
+
16
+ include ChemistryParadise::Constants
17
+ include ChemistryParadise::Shared
18
+
19
+ alias ee print
20
+
21
+ # ========================================================================= #
22
+ # === NAMESPACE
23
+ # ========================================================================= #
24
+ NAMESPACE = inspect
25
+
26
+ # ========================================================================= #
27
+ # === FILE_MOLECULAR_FORMULA_OF_DIFFERENT_MOLECULES
28
+ # ========================================================================= #
29
+ FILE_MOLECULAR_FORMULA_OF_DIFFERENT_MOLECULES =
30
+ "#{PROJECT_BASE_DIRECTORY}yaml/molecular_formula_of_different_molecules.yml"
31
+
32
+ # ========================================================================= #
33
+ # === reset
34
+ # ========================================================================= #
35
+ def reset
36
+ end
37
+
38
+ # ========================================================================= #
39
+ # === opnn
40
+ # ========================================================================= #
41
+ def opnn(i)
42
+ if i.is_a? String
43
+ i = { namespace: i }
44
+ end
45
+ Opn.opn(i) # Delegate to module Opn here.
46
+ end
47
+
48
+ # ========================================================================= #
49
+ # === use_which_language?
50
+ # ========================================================================= #
51
+ def use_which_language?
52
+ ::ChemistryParadise.use_which_language?
53
+ end
54
+
55
+ # ========================================================================= #
56
+ # === do_use_the_german_language
57
+ # ========================================================================= #
58
+ def do_use_the_german_language
59
+ ::ChemistryParadise.do_use_german
60
+ end
61
+
62
+ # ========================================================================= #
63
+ # === do_use_the_english_language
64
+ # ========================================================================= #
65
+ def do_use_the_english_language
66
+ ::ChemistryParadise.do_use_english
67
+ end
68
+
69
+ # ========================================================================= #
70
+ # === do_we_use_english?
71
+ #
72
+ # Query method to determine whether we will use english or whether
73
+ # we will use another language, for a project-wide setting.
74
+ # ========================================================================= #
75
+ def do_we_use_english?
76
+ (use_which_language? == :english)
77
+ end
78
+
79
+ # ========================================================================= #
80
+ # === set_commandline_arguments
81
+ # ========================================================================= #
82
+ def set_commandline_arguments(i = '')
83
+ i = [i].flatten.compact
84
+ @commandline_arguments = i
85
+ end
86
+
87
+ # ========================================================================= #
88
+ # === commandline_arguments?
89
+ # ========================================================================= #
90
+ def commandline_arguments?
91
+ @commandline_arguments
92
+ end
93
+
94
+ # ========================================================================= #
95
+ # === first_argument?
96
+ # ========================================================================= #
97
+ def first_argument?
98
+ @commandline_arguments.first
99
+ end; alias first? first_argument? # === first?
100
+
101
+ end; end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'chemistry_paradise/base/colours.rb'
6
+ # =========================================================================== #
7
+ module ChemistryParadise
8
+
9
+ class Base # === ChemistryParadise::Base
10
+
11
+ begin
12
+ require 'colours'
13
+ include Colours
14
+ rescue LoadError; end
15
+
16
+ # ========================================================================= #
17
+ # === rev
18
+ # ========================================================================= #
19
+ def rev
20
+ ::Colours.rev
21
+ end
22
+
23
+ # ========================================================================= #
24
+ # === grey
25
+ # ========================================================================= #
26
+ def grey(i)
27
+ "#{Colours::GREY}#{i}#{Colours}#{rev}"
28
+ end
29
+
30
+ # ========================================================================= #
31
+ # === royalblue
32
+ # ========================================================================= #
33
+ def royalblue(i)
34
+ ::Colours.royalblue(i)
35
+ end
36
+
37
+ # ========================================================================= #
38
+ # === steelblue
39
+ # ========================================================================= #
40
+ def steelblue(i)
41
+ ::Colours.steelblue(i)
42
+ end
43
+
44
+ # ========================================================================= #
45
+ # === yellow
46
+ # ========================================================================= #
47
+ def yellow(i)
48
+ ::Colours.yellow(i)
49
+ end
50
+
51
+ # ========================================================================= #
52
+ # === teal
53
+ # ========================================================================= #
54
+ def teal(i)
55
+ Colours.teal(i)
56
+ end
57
+
58
+ # ========================================================================= #
59
+ # === sfancy
60
+ # ========================================================================= #
61
+ def sfancy(i)
62
+ ::Colours.sfancy(i)
63
+ end
64
+
65
+ end; end
@@ -0,0 +1,487 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ChemistryParadise::CalculateAtomicMass
6
+ #
7
+ # This class will calculate the atomic mass of a compound.
8
+ # =========================================================================== #
9
+ # require 'chemistry_paradise/calculate_atomic_mass.rb'
10
+ # =========================================================================== #
11
+ require 'chemistry_paradise/base/base.rb'
12
+ require 'chemistry_paradise/split_molecule_names.rb'
13
+
14
+ module ChemistryParadise
15
+
16
+ class CalculateAtomicMass < Base # === ChemistryParadise::CalculateAtomicMass
17
+
18
+ # ========================================================================= #
19
+ # === NAMESPACE
20
+ # ========================================================================= #
21
+ NAMESPACE = inspect
22
+
23
+ # ========================================================================= #
24
+ # === ARRAY_HELP_OPTIONS
25
+ # ========================================================================= #
26
+ ARRAY_HELP_OPTIONS = %w(
27
+ HELP help --help --h -h
28
+ )
29
+
30
+ # ========================================================================= #
31
+ # === ATOMGEWICHTE
32
+ # ========================================================================= #
33
+ _ = Constants::FILE_ATOMGEWICHTE
34
+ if File.exist? _
35
+ ATOMGEWICHTE = YAML.load_file(_)
36
+ elsif File.exist? File.expand_path('~')+File.basename(_)
37
+ ATOMGEWICHTE = YAML.load_file(File.expand_path('~')+File.basename(_))
38
+ end
39
+
40
+ # ========================================================================= #
41
+ # === ChemistryParadise::CalculateAtomicMass::DEFAULT_INPUT
42
+ # ========================================================================= #
43
+ DEFAULT_INPUT = 'P2O5'
44
+
45
+ # ========================================================================= #
46
+ # === initialize
47
+ # ========================================================================= #
48
+ def initialize(
49
+ optional_input = ARGV,
50
+ run_already = true
51
+ )
52
+ reset
53
+ set_input(optional_input)
54
+ case run_already.to_s
55
+ when 'do_not_report'
56
+ @report_result = false
57
+ run_already = true
58
+ end
59
+ run if run_already
60
+ end
61
+
62
+ # ========================================================================= #
63
+ # === reset
64
+ # ========================================================================= #
65
+ def reset
66
+ super()
67
+ # ======================================================================= #
68
+ # === @commandline_arguments
69
+ # ======================================================================= #
70
+ @commandline_arguments = []
71
+ # ======================================================================= #
72
+ # === @show_more
73
+ # ======================================================================= #
74
+ @show_more = true
75
+ # ======================================================================= #
76
+ # === @show_the_steps
77
+ #
78
+ # If the following variable is set to true then we will display,
79
+ # on the commandline, what is done when. This gives the user more
80
+ # information about what is going on, and it may also help during
81
+ # debugging this class/project.
82
+ #
83
+ # Note that @show_the_steps is a bit different to @show_more, so
84
+ # these two variables are presently kept separate.
85
+ # ======================================================================= #
86
+ @show_the_steps = false
87
+ # ======================================================================= #
88
+ # === @individual_components
89
+ # ======================================================================= #
90
+ @individual_components = []
91
+ # ======================================================================= #
92
+ # === @output_string
93
+ # ======================================================================= #
94
+ @output_string = ''.dup
95
+ # ======================================================================= #
96
+ # === @report_result
97
+ # ======================================================================= #
98
+ @report_result = true
99
+ # ======================================================================= #
100
+ # === @molecular_formula_of_different_molecules
101
+ # ======================================================================= #
102
+ @molecular_formula_of_different_molecules = YAML.load_file(
103
+ FILE_MOLECULAR_FORMULA_OF_DIFFERENT_MOLECULES
104
+ )
105
+ set_input
106
+ end
107
+
108
+ # ========================================================================= #
109
+ # === set_input
110
+ # ========================================================================= #
111
+ def set_input(i = DEFAULT_INPUT)
112
+ if i.is_a? Array
113
+ @commandline_arguments = i[1..-1] # Set the remaining as commandline arguments.
114
+ i = i.first # And re-assign the first input.
115
+ end
116
+ i = DEFAULT_INPUT if i.nil?
117
+ case i.to_s
118
+ when 'do_not_report'
119
+ @report_result = false
120
+ i = nil
121
+ when 'harnstoff'
122
+ i = @molecular_formula_of_different_molecules['harnstoff']
123
+ end
124
+ i = ARRAY_TEST_THESE_MOLECULES if i == :test_default_molecules
125
+ i = i.to_s.dup
126
+ # if i.include? ', '
127
+ # i = i.split(',').map(&:strip)
128
+ # end
129
+ # i = [i] unless i.is_a? Array
130
+ @input = i
131
+ sanitize_input
132
+ end
133
+
134
+ # ========================================================================= #
135
+ # === input?
136
+ # ========================================================================= #
137
+ def input?
138
+ @input
139
+ end
140
+
141
+ # ========================================================================= #
142
+ # === sanitize_input_for_element_names
143
+ # ========================================================================= #
144
+ def sanitize_input_for_element_names(array)
145
+ result = []
146
+ if array.any? {|entry| entry == entry.downcase }
147
+ array.each {|entry|
148
+ case entry
149
+ when *ARRAY_HELP_OPTIONS
150
+ show_help :then_exit
151
+ end
152
+ if entry == entry.downcase
153
+ result[-1] = result[-1]+entry
154
+ else
155
+ result << entry
156
+ end
157
+ }
158
+ else
159
+ result = array
160
+ end
161
+ return result
162
+ end
163
+
164
+ # ========================================================================= #
165
+ # === calculate_compound
166
+ #
167
+ # This method will attempt to calculate the given input.
168
+ #
169
+ # The input to this method will usually be something like "Pb3".
170
+ # ========================================================================= #
171
+ def calculate_compound(i)
172
+ result = 0
173
+ if i =~ /\d+/ # if input has a number
174
+ splitted = i.split(/(\d+)/)
175
+ else # else assume that the number is one.
176
+ splitted = [ i, 1 ]
177
+ end
178
+ if atomgewichte?.has_key? splitted[0]
179
+ result = splitted[1].to_i * ATOMGEWICHTE[splitted[0]]
180
+ end
181
+ gather_individual_components(i, result)
182
+ return result
183
+ end; alias ba calculate_compound # === ba
184
+ alias summenformel calculate_compound # === summenformel
185
+ alias atomgewicht calculate_compound # === atomgewicht
186
+ alias molmasse calculate_compound # === molmasse
187
+ alias molare_masse calculate_compound # === molare_masse
188
+ alias calculcate_molecular_weight calculate_compound # === calculcate_molecular_weight
189
+
190
+ # ========================================================================= #
191
+ # === atomgewichte?
192
+ # ========================================================================= #
193
+ def atomgewichte?
194
+ ATOMGEWICHTE
195
+ end
196
+
197
+ # ========================================================================= #
198
+ # === set_result
199
+ # ========================================================================= #
200
+ def set_result(i)
201
+ @result = i
202
+ end
203
+
204
+ # ========================================================================= #
205
+ # === report_result
206
+ # ========================================================================= #
207
+ def report_result
208
+ e @output_string
209
+ end
210
+
211
+ # ========================================================================= #
212
+ # === gather_individual_components
213
+ # ========================================================================= #
214
+ def gather_individual_components(name, weight)
215
+ array = [name, weight]
216
+ @individual_components << array
217
+ end
218
+
219
+ # ========================================================================= #
220
+ # === bold_red
221
+ # ========================================================================= #
222
+ def bold_red(i)
223
+ swarn(i)
224
+ end
225
+
226
+ # ========================================================================= #
227
+ # === nice_result
228
+ # ========================================================================= #
229
+ def nice_result
230
+ @result.to_f.round(3).to_s
231
+ end
232
+
233
+ # ========================================================================= #
234
+ # === is_included?
235
+ # ========================================================================= #
236
+ def is_included?(i = input?)
237
+ i = i[0,2] if i.size > 2 # Take only the first two characters, in the event that we have more than two characters in the supplied input.
238
+ atomgewichte?.has_key?(i)
239
+ end; alias include? is_included? # === include?
240
+
241
+ # ========================================================================= #
242
+ # === report_that_this_element_does_not_exist
243
+ # ========================================================================= #
244
+ def report_that_this_element_does_not_exist(i)
245
+ opnn; e 'The given element at `'+sfancy(i.to_s)+'` does not exist.'
246
+ exit
247
+ end
248
+
249
+ # ========================================================================= #
250
+ # === report_result?
251
+ # ========================================================================= #
252
+ def report_result?
253
+ @report_result
254
+ end
255
+
256
+ # ========================================================================= #
257
+ # === result?
258
+ # ========================================================================= #
259
+ def result?
260
+ @result
261
+ end; alias result result? # === result
262
+ alias masse? result? # === masse?
263
+
264
+ # ========================================================================= #
265
+ # === menu (menu tag)
266
+ #
267
+ # The @commandline_arguments will be checked against the internal menu.
268
+ # ========================================================================= #
269
+ def menu(i = @commandline_arguments)
270
+ if i.is_a? Array
271
+ i.each {|entry| menu(entry) }
272
+ else
273
+ case i # case tag
274
+ # ===================================================================== #
275
+ # === molmasse C5H6N2O2 --show-steps
276
+ # ===================================================================== #
277
+ when /^-?-?show(-|_)?steps$/
278
+ do_show_the_steps
279
+ # ===================================================================== #
280
+ # === molmasse C5H6N2O2 --show-details
281
+ # ===================================================================== #
282
+ when /^-?-?show(-|_)?details?$/,
283
+ '--detail'
284
+ do_show_details
285
+ # ===================================================================== #
286
+ # === molmasse --help
287
+ # ===================================================================== #
288
+ when *ARRAY_HELP_OPTIONS
289
+ show_help
290
+ exit
291
+ # ===================================================================== #
292
+ # === molmasse SUM
293
+ # ===================================================================== #
294
+ when 'SUM','SHOW','MORE'
295
+ do_show_details
296
+ end
297
+ end
298
+ end; alias check_against_menu menu # === check_against_menu
299
+
300
+ # ========================================================================= #
301
+ # === do_show_details
302
+ # ========================================================================= #
303
+ def do_show_details
304
+ @show_more = true
305
+ end
306
+
307
+ # ========================================================================= #
308
+ # === opnn
309
+ # ========================================================================= #
310
+ def opnn
311
+ super(NAMESPACE)
312
+ end
313
+
314
+ # ========================================================================= #
315
+ # === determine_output_string
316
+ #
317
+ # This method will determine the String that will be shown to the
318
+ # user on the commandline.
319
+ # ========================================================================= #
320
+ def determine_output_string
321
+ _ = nice_result
322
+ if do_we_use_english?
323
+ @output_string = "The molecular mass of #{sfancy(@input)} is "\
324
+ "#{simp(_+' u (g / mol)')}."
325
+ else # then we probably use german
326
+ @output_string = "#{rev}Die molekulare Masse von #{sfancy(@input)} "\
327
+ "beträgt #{simp(_+' u (g / mol)')}."
328
+ end
329
+ end
330
+
331
+ # ========================================================================= #
332
+ # === show_help
333
+ # ========================================================================= #
334
+ def show_help(i = :then_exit)
335
+ opn; e 'Pass -SUM to show the individual sub-steps as well.'
336
+ exit if i == :then_exit
337
+ end
338
+
339
+ # ========================================================================= #
340
+ # === consider_modifying_the_output_string
341
+ # ========================================================================= #
342
+ def consider_modifying_the_output_string
343
+ if @show_more # This can modify the output string.
344
+ _ = ''.dup
345
+ Hash[@individual_components].each_pair {|key, value|
346
+ key = key.scan(/./).map {|entry|
347
+ if entry =~ /^\d+/ # Starts with a number.
348
+ entry << 'x'
349
+ end
350
+ entry
351
+ }
352
+ key = key.join
353
+ _ << key+': '+value.round(7).to_s+' | '
354
+ }
355
+ @output_string = @output_string.dup if @output_string.frozen?
356
+ @output_string << "#{N}#{bold_red(' (The individual components were: ').dup}#{rev}"
357
+ _.strip!
358
+ splitted = _.split('|').map {|entry|
359
+ Colours.kde_colour_palette_plasma_blue(entry)
360
+ }
361
+ joined = splitted.join(teal('|'))
362
+ @output_string << joined+
363
+ bold_red(')')
364
+ end
365
+ end
366
+
367
+ # ========================================================================= #
368
+ # === calculate_result
369
+ #
370
+ # Use this method to calculate the result (the molecular mass).
371
+ # ========================================================================= #
372
+ def calculate_result
373
+ mass_number = 0
374
+ splitted = SplitMoleculeNames.new(input?).result
375
+ splitted = sanitize_input_for_element_names(splitted)
376
+ splitted.each {|entry|
377
+ add_this_amount = calculate_compound(entry)
378
+ if @show_the_steps
379
+ e "#{rev}Now adding #{royalblue(add_this_amount)} for the "\
380
+ "compound #{steelblue(entry)}."
381
+ end
382
+ mass_number += add_this_amount
383
+ }
384
+ set_result(mass_number)
385
+ determine_output_string
386
+ end; alias calculate calculate_result # === calculate
387
+
388
+ # ========================================================================= #
389
+ # === do_show_the_steps
390
+ # ========================================================================= #
391
+ def do_show_the_steps
392
+ @show_the_steps = true
393
+ end
394
+
395
+ # ========================================================================= #
396
+ # === sanitize_input
397
+ #
398
+ # This method will presently sanitize the input, by working on ₂ and
399
+ # on ₃, and replace these with the corresponding numbers. This may
400
+ # be useful depending on the chemical formula at hand, such as
401
+ # carbon dioxide (CO₂).
402
+ # ========================================================================= #
403
+ def sanitize_input
404
+ @input.tr!('₂','2') if @input.include? '₂'
405
+ @input.tr!('₃','3') if @input.include? '₃'
406
+ @input.tr!('₄','4') if @input.include? '₄'
407
+ end
408
+
409
+ # ========================================================================= #
410
+ # === run (run tag)
411
+ # ========================================================================= #
412
+ def run
413
+ check_against_menu
414
+ use_this_input = input?
415
+ if use_this_input.to_s.size < 3
416
+ unless is_included?
417
+ report_that_this_element_does_not_exist(use_this_input)
418
+ end
419
+ end
420
+ calculate_result
421
+ consider_modifying_the_output_string
422
+ report_result if report_result?
423
+ end
424
+
425
+ # ========================================================================= #
426
+ # === CalculateAtomicMass[]
427
+ # ========================================================================= #
428
+ def self.[](i)
429
+ parse(i)
430
+ end
431
+
432
+ # ========================================================================= #
433
+ # === CalculateAtomicMass.parse
434
+ # ========================================================================= #
435
+ def self.parse(i)
436
+ _ = CalculateAtomicMass.new(i, false)
437
+ _.calculate
438
+ return _.nice_result
439
+ end
440
+
441
+ end
442
+
443
+ # =========================================================================== #
444
+ # === ChemistryParadise.atomic_mass_of
445
+ #
446
+ # This method is a shortcut, to quickly calculate the molecular mass of
447
+ # a compound. See the usage example that follows.
448
+ #
449
+ # Usage example:
450
+ #
451
+ # ChemistryParadise.atomic_mass_of 'C10H13N5O3' # => "251.245"
452
+ #
453
+ # =========================================================================== #
454
+ def self.atomic_mass_of(i)
455
+ ChemistryParadise::CalculateAtomicMass.parse(i)
456
+ end; self.instance_eval { alias return_molmasse atomic_mass_of } # === Chemistry.return_molmasse
457
+ self.instance_eval { alias molmass_of? atomic_mass_of } # === Chemistry.molmass_of?
458
+
459
+ end
460
+
461
+ if __FILE__ == $PROGRAM_NAME
462
+ include ChemistryParadise
463
+ if ARGV.empty?
464
+ alias e puts
465
+ opn; e 'Running some tests now as no input was given to us.'
466
+ # ======================================================================= #
467
+ # === test_me
468
+ # ======================================================================= #
469
+ def test_me(i)
470
+ puts sprintf(' The mass number of %-4s is %3s',
471
+ i,
472
+ CalculateAtomicMass.new(i).result.to_s
473
+ )
474
+ end
475
+ cliner {
476
+ e 'Nun berechnen wir einige Atomgewichte:'
477
+ ARRAY_TEST_THESE_MOLECULES.each {|entry| test_me(entry) }
478
+ }
479
+ e 'Das Atomgewicht von C12H12N2 ist: '
480
+ e ' → '+test_me('C12H12N2').to_s
481
+ else
482
+ _ = CalculateAtomicMass.new(ARGV)
483
+ end
484
+ end # mmasse T
485
+ # mmasse C16H12N2
486
+ # mmasse CH₃Cl
487
+ # mmasse CaCO3 --show-steps