class ChemistryParadise::ShowElectronConfiguration

Constants

DEFAULT_INPUT
#

DEFAULT_INPUT

#
MAIN_HASH
#
  1. Periode: 1s

  2. Periode: 2s 2p

  3. Periode: 3s 3p

  4. Periode: 4s 3d 4p

  5. Periode: 5s 4d 5p

  6. Periode: 6s 4f 5d 6p

  7. Periode: 7s 5f 6d

#

The following hash was taken from:

http://en.wikipedia.org/wiki/Electron_configuration#Other_exceptions_to_Madelung.27s_rule

and from:

http://en.wikipedia.org/wiki/Electron_configurations_of_the_elements_%28data_page%29
#
NEBENQUANTENZAHL
#

NEBENQUANTENZAHL

#
PERIODIC_TABLE
#

PERIODIC_TABLE

#

Public Class Methods

new( optional_input = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 122
def initialize(
    optional_input = nil,
    run_already    = true
  )
  reset
  set_input(optional_input)
  run if run_already
end

Public Instance Methods

check_for_inclusion() click to toggle source
#

check_for_inclusion

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 193
def check_for_inclusion
  if periodic_table?.has_key? @input
    set_n_electrons periodic_table?[@input]
    e 'Found element '+sfancy(@input)+'. '+
      'It has '+simp(@n_electrons.to_s)+' electrons.'
    display_electron_configuration(@n_electrons)
  else
    e "Did not find element called `#{sfancy(@input)}`."
  end
end
default_colour() click to toggle source
#

default_colour

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 179
def default_colour
  Colours::GREY
end
display_electron_configuration(i = @n_electrons) click to toggle source
#

display_electron_configuration

Show the specific electron configuration.

For instance:

1s2 2s2 2p6 3s2 3p4
#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 212
def display_electron_configuration(i = @n_electrons)
  # ======================================================================= #
  # Notify the user of invalid input.
  # ======================================================================= #
  unless main_hash?.has_key? i
    e 'Note that the electron at position '+i.to_s+
      ' is not registered.'
  end
  set_main_string MAIN_HASH[i]
  # ======================================================================= #
  # Output it next:
  # ======================================================================= #
  e yellow(@_)
end
main_hash?() click to toggle source
#

main_hash?

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 186
def main_hash?
  MAIN_HASH
end
periodic_table?() click to toggle source
#

periodic_table?

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 172
def periodic_table?
  PERIODIC_TABLE
end
reset() click to toggle source
#

reset

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 134
def reset
  @n_electrons = 0
  @_ = '' # The result string.
end
run() click to toggle source
#

run (run tag)

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 230
def run
  check_for_inclusion
end
set_input(i = N) click to toggle source
#

set_input

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 149
def set_input(i = N)
  i = i.first if i.is_a? Array
  i = DEFAULT_INPUT if i.nil?
  i = i.to_s.dup.delete('/') # We don't need '/' characters.
  i = periodic_table?.invert[i.to_i] if i =~ /^\d+$/
  # ======================================================================= #
  # Since as of June 2016, we will upcase the first character.
  # ======================================================================= #
  i = i.dup if i.frozen?
  i[0,1] = i[0,1].upcase
  @input = i
end
set_main_string(i) click to toggle source
#

set_main_string

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 142
def set_main_string(i)
  @_ = i
end
set_n_electrons(i) click to toggle source
#

set_n_electrons

#
# File lib/chemistry_paradise/show_electron_configuration.rb, line 165
def set_n_electrons(i)
  @n_electrons = i
end