Class: ChemistryParadise::ShowElement

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

Overview

ChemistryParadise::ShowElement

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect
PERIODIC_TABLE =
#

PERIODIC_TABLE

#
YAML.load_file(ChemistryParadise::Constants::FILE_PERIODIC_TABLE_OF_THE_ELEMENTS)

Constants inherited from Base

Base::FILE_MOLECULAR_FORMULA_OF_DIFFERENT_MOLECULES

Constants included from Shared

ChemistryParadise::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, #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) ⇒ ShowElement

#

initialize

#


37
38
39
40
41
42
43
44
# File 'lib/chemistry_paradise/show_element.rb', line 37

def initialize(
    i           = nil,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Instance Method Details

#new_position?Boolean

#

new_position?

#

Returns:

  • (Boolean)


100
101
102
# File 'lib/chemistry_paradise/show_element.rb', line 100

def new_position?
  @relative_position
end

#opnnObject

#

opnn

#


137
138
139
# File 'lib/chemistry_paradise/show_element.rb', line 137

def opnn
  super(NAMESPACE)
end

#process_inputObject

#

process_input

#


75
76
77
78
79
80
81
82
83
# File 'lib/chemistry_paradise/show_element.rb', line 75

def process_input
  if    @input.include? '+'
    set_batch('+')
  elsif @input.include? '-'
    set_batch('-')
  else
    set_name_of_the_element(@input)
  end
end

#report_resultObject

#

report_result

#


107
108
109
110
111
112
# File 'lib/chemistry_paradise/show_element.rb', line 107

def report_result
  current_position = PERIODIC_TABLE[@name_of_the_element]
  current_position = current_position + new_position?
  opnn; e PERIODIC_TABLE.invert[current_position]+' is at position '+
          sfancy(current_position.to_s)+'.'
end

#resetObject

#

reset (reset tag)

#


49
50
51
52
# File 'lib/chemistry_paradise/show_element.rb', line 49

def reset
  set_name_of_the_element
  set_relative_position
end

#runObject

#

run

#


130
131
132
# File 'lib/chemistry_paradise/show_element.rb', line 130

def run # (run tag)
  report_result
end

#set_batch(on_which_token = '+') ⇒ Object

#

set_batch

This will set both (1) the name and (2) the relative position.

#


90
91
92
93
94
95
# File 'lib/chemistry_paradise/show_element.rb', line 90

def set_batch(on_which_token = '+')
  _ = @input.split(on_which_token)
  set_name_of_the_element _[0]
  _[1] = '-'+_[1].to_s if on_which_token == '-'
  set_relative_position   _[1]
end

#set_input(i = '') ⇒ Object

#

set_input

#


57
58
59
60
61
62
# File 'lib/chemistry_paradise/show_element.rb', line 57

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup if i
  @input = i
  process_input
end

#set_name_of_the_element(i = nil) ⇒ Object

#

set_name_of_the_element

#


117
118
119
120
121
122
123
124
125
# File 'lib/chemistry_paradise/show_element.rb', line 117

def set_name_of_the_element(i = nil)
  # ======================================================================= #
  # if the input is a number, we invert the PERIODIC_TABLE.
  # ======================================================================= #
  if i =~ /^\d+$/
    i = PERIODIC_TABLE.invert[i.to_i]
  end
  @name_of_the_element = i
end

#set_relative_position(i = 0) ⇒ Object

#

set_relative_position

#


67
68
69
70
# File 'lib/chemistry_paradise/show_element.rb', line 67

def set_relative_position(i = 0)
  i = i.to_i if i
  @relative_position = i
end