Class: ChemistryParadise::CombustionAnalysis

Inherits:
Base
  • Object
show all
Defined in:
lib/chemistry_paradise/utility_scripts/combustion_analysis.rb

Overview

ChemistryParadise::CombustionAnalysis

Constant Summary

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

ChemistryParadise::Constants::ELECTRON_NEGATIVITY_CHART, ChemistryParadise::Constants::FILE_ATOMGEWICHTE, ChemistryParadise::Constants::FILE_ELECTRON_NEGATIVITY_CHART, ChemistryParadise::Constants::FILE_PERIODIC_TABLE_OF_THE_ELEMENTS, ChemistryParadise::Constants::N, ChemistryParadise::Constants::PLANK_CONSTANT, ChemistryParadise::Constants::PROPER_FILLORDER, ChemistryParadise::Constants::SPEED_OF_LIGHT

Class Method Summary collapse

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(commandline_arguments = nil, run_already = true) ⇒ CombustionAnalysis

#

initialize

#


27
28
29
30
31
32
33
34
35
36
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 27

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

CombustionAnalysis[]

#


198
199
200
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 198

def self.[](i = '')
  new(i)
end

Instance Method Details

#determine_the_resultObject

#

determine_the_result

#


148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 148

def determine_the_result
  @result = @hash_ratio.map {|k, v|
    v = v.to_i
    case v
    when 1
      v = ''
    when 2
      v = ''
    when 3
      v = ''
    when 4
      v = ''
    when 5
      v = ''
    when 6
      v = ''
    when 7
      v = ''
    when 8
      v = ''
    when 9
      v = ''
    when 12
      v = '₁₂'
    end
    "#{k}#{v}"
  }.join
end

#does_the_main_hash_have_an_uneven_value?Boolean

#

does_the_main_hash_have_an_uneven_value?

This method will return true if we have an uneven value in the main Hash, such as 1.5.

#

Returns:

  • (Boolean)


125
126
127
128
129
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 125

def does_the_main_hash_have_an_uneven_value?
  @hash_ratio.values.any? {|entry|
    (entry - entry.floor) > 0
  }
end

#further_process_the_main_hashObject

#

further_process_the_main_hash

This method is specifically to turn e. g. a 1.5 into a 3.0.

#


102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 102

def further_process_the_main_hash
  first_zero_point_result = @hash_ratio.select {|key, value|
    value - value.floor == 0.5
  }
  if first_zero_point_result
    # ===================================================================== #
    # This may be:
    #
    #   {"S"=>1.5}
    #
    # ===================================================================== #
    @hash_ratio.transform_values! {|value|
      value * 2.0
    }
  end
end

#hash_ratio?Boolean Also known as: hash?

#

hash_ratio?

#

Returns:

  • (Boolean)


134
135
136
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 134

def hash_ratio?
  @hash_ratio
end

#parse_the_main_input(i) ⇒ Object

#

parse_the_main_input

#


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 52

def parse_the_main_input(i)
  dataset = YAML.load_file(FILE_ATOMGEWICHTE)
  # ======================================================================= #
  # Currently we require that the String has '%' inserted appropriately.
  # ======================================================================= #
  if i.is_a?(String) and i.include?('%')
    splitted = i.split('%').map(&:strip)
    # ===================================================================== #
    # splitted is now:
    #
    #   ["K 28,93", "S 23,72", "O 47.35"]
    #
    # ===================================================================== #
    splitted.each {|entry|
      entry.tr!(',','.')
      inner_splitted = entry.split(' ')
      first = inner_splitted.first
      last  = inner_splitted.last.to_f
      @hash_ratio[first] = last / dataset[first]
    }
  end
end

#reportObject

#

report

#


141
142
143
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 141

def report
  e @result
end

#resetObject

#

reset (reset tag)

#


41
42
43
44
45
46
47
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 41

def reset
  super()
  # ======================================================================= #
  # === @hash_ratio
  # ======================================================================= #
  @hash_ratio = {}
end

#result?Boolean

#

result?

#

Returns:

  • (Boolean)


180
181
182
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 180

def result?
  @result
end

#runObject

#

run (run tag)

#


187
188
189
190
191
192
193
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 187

def run
  _ = first?
  parse_the_main_input(_)
  work_on_the_hash_ratio
  determine_the_result
  report
end

#work_on_the_hash_ratioObject

#

work_on_the_hash_ratio

#


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/chemistry_paradise/utility_scripts/combustion_analysis.rb', line 78

def work_on_the_hash_ratio
  # ======================================================================= #
  # The Hash may look like this:
  #
  #   { "K"=>0.7399355465752724,
  #     "S"=>0.7397473881178855,
  #     "O"=>2.959559972498281}
  #
  # ======================================================================= #
  min_element = @hash_ratio.min
  ratio = 1.0 / min_element.last
  @hash_ratio.transform_values! {|values|
    (values * ratio).round(1)
  }
  if does_the_main_hash_have_an_uneven_value?
    further_process_the_main_hash
  end
end