Class: ChemistryParadise::ParseCommandline

Inherits:
Base
  • Object
show all
Defined in:
lib/chemistry_paradise/commandline/menu.rb,
lib/chemistry_paradise/commandline/help.rb,
lib/chemistry_paradise/commandline/parse_commandline.rb

Overview

ChemistryParadise::ParseCommandline

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

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(optional_input = ARGV, run_already = true) ⇒ ParseCommandline

#

initialize

#


22
23
24
25
26
27
28
29
# File 'lib/chemistry_paradise/commandline/parse_commandline.rb', line 22

def initialize(
    optional_input = ARGV,
    run_already    = true
  )
  set_commandline(optional_input)
  reset
  run if run_already
end

Instance Method Details

#berechne_atomgewicht(i) ⇒ Object

#

berechne_atomgewicht

#


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/chemistry_paradise/commandline/parse_commandline.rb', line 68

def berechne_atomgewicht(i)
  pp i
  if i.is_a? Array
    i.flatten.each {|entry|
      berechne_atomgewicht(i)
    }
  else
    if i == :test_default_molecules
      i = ARRAY_TEST_THESE_MOLECULES
    end
    if i.is_a? Array
      berechne_atomgewicht(i)
    else
      e sprintf(
        'The mass number of %-4s is %3s',
        i,
        ChemistryParadise::CalculateAtomicMass.new(i).result.to_s
      )
    end
  end
end
#

menu (menu tag)

#


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/chemistry_paradise/commandline/menu.rb', line 22

def menu(
    i = @commandline
  )
  if i.is_a? Array
    i.each {|entry| menu(entry) }
  else
    case i
    # ===================================================================== #
    # === chemistry_paradise --gtk-calculate-molecular-weight
    # ===================================================================== #
    when /^-?-?gtk(_|-)?calculate(_|-)?molecular(_|-)?weight$/i
      require 'chemistry_paradise/gui/gtk3/calculate_molecular_weight/calculate_molecular_weight.rb'
      ChemistryParadise::GUI::Gtk::CalculateMolecularWeight.run
      exit
    # ===================================================================== #
    # === chemistry_paradise --periodic-table
    # ===================================================================== #
    when /^-?-?periodic(_|-)?table$/i
      show_the_periodic_table
      exit
    # ===================================================================== #
    # === chemistry_paradise --electronegativity-of=F/Fe
    # ===================================================================== #
    when /-?-?electronegativity(_|-)?of=(.+)/
      these_elements = $2.to_s.dup.strip
      if these_elements.include? '/'
        these_elements = these_elements.split('/')
      end
      ChemistryParadise::ShowElectronNegativityOfThisElement.new(these_elements)
    # ===================================================================== #
    # === chemistry_paradise show_electron_negativity_chart
    # ===================================================================== #
    when /show(_|-)?electron(_|-)?negativity(_|-)?chart/
      show_electron_negativity_chart
    # ===================================================================== #
    # === chemistry_paradise test_which_molecules?
    # ===================================================================== #
    when /test(_|-)?which(_|-)?molecules\??/
      pp ARRAY_TEST_THESE_MOLECULES
    # ===================================================================== #
    # === chemistry_paradise --molmassen?
    # ===================================================================== #
    when /molmassen\??/,
         /display(_|-)?molmassen(_|-)?file/,
         /display(_|-)?where(_|-)?the(_|-)?molmasses(_|-)?are(_|-)?kept/
      ::ChemistryParadise.display_where_the_molmasses_are_kept
    # ===================================================================== #
    # === chemistry_paradise --help
    # ===================================================================== #
    when /^-?-?help/
      show_help
    else
      if i.start_with?('/') and i.end_with?('/')
        # ================================================================= #
        # Assume this to be a pseudo-regex.
        # ================================================================= #
        search_for_this_element = i.delete('/').capitalize
        _ = ChemistryParadise.return_element_symbol_from_this_german_name(search_for_this_element)
        if _
          e simp(search_for_this_element)+' corresponds to '+sfancy(_)+'.'
        end
      end
    end
  end
end

#resetObject

#

reset

#


34
35
36
# File 'lib/chemistry_paradise/commandline/parse_commandline.rb', line 34

def reset
  super()
end

#runObject

#

run

#


61
62
63
# File 'lib/chemistry_paradise/commandline/parse_commandline.rb', line 61

def run
  menu
end

#set_commandline(i) ⇒ Object

#

set_commandline

#


53
54
55
56
# File 'lib/chemistry_paradise/commandline/parse_commandline.rb', line 53

def set_commandline(i)
  i = [i] unless i.is_a? Array
  @commandline = i
end

#show_helpObject

#

show_help

The help options can be queried via:

chemistry_paradise --help
#


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chemistry_paradise/commandline/help.rb', line 19

def show_help
  e 'The following options are documented:'
  e
  e '  --molmassen?                     # show '\
    'where the molmasses are kept (a file)'
  e '  --electronegativity-of=F/Fe      # report '\
    'the electronegativitiy of the elements F '\
    'and Fe (Fluor and Iron)'
  e '  --show_electron_negativity_chart # show '\
    'the electron negativity chart of the atoms'
  e '  --gtk-calculate-molecular-weight # to start '\
    'the ruby-gtk3 wrapper for calculating the '\
    'weight of compounds'
  e '  /Quecksilber/                    # use '\
    'a pseudo-regex to obtain the element-symbol '\
    'from a german name'
  e '  ^^^ the above // is called a pseudo-regex; pseudo '\
    'because it is actually a String and not a regex'
  e
end

#show_the_periodic_tableObject

#

show_the_periodic_table

#


41
42
43
44
45
46
47
48
# File 'lib/chemistry_paradise/commandline/parse_commandline.rb', line 41

def show_the_periodic_table
  _ = ::ChemistryParadise.periodic_table?
  if File.exist? _
    YAML.load_file(_).each_pair {|key, value|
      e '  '+(key.to_s+ ':').ljust(3)+' '+value.to_s.rjust(2)
    }
  end
end