Class: ChemistryParadise::ShowElement
- Inherits:
-
Base
- Object
- Base
- ChemistryParadise::ShowElement
show all
- Defined in:
- lib/chemistry_paradise/show_element.rb
Overview
ChemistryParadise::ShowElement
Constant Summary
collapse
- NAMESPACE =
inspect
- 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
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
100
101
102
|
# File 'lib/chemistry_paradise/show_element.rb', line 100
def new_position?
@relative_position
end
|
#opnn ⇒ Object
137
138
139
|
# File 'lib/chemistry_paradise/show_element.rb', line 137
def opnn
super(NAMESPACE)
end
|
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_result ⇒ Object
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
|
#reset ⇒ Object
49
50
51
52
|
# File 'lib/chemistry_paradise/show_element.rb', line 49
def reset
set_name_of_the_element
set_relative_position
end
|
#run ⇒ Object
130
131
132
|
# File 'lib/chemistry_paradise/show_element.rb', line 130
def run 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
|
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 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
|