Class: LittleElementor::Element
- Inherits:
-
Object
- Object
- LittleElementor::Element
- Includes:
- Helpers
- Defined in:
- lib/little_elementor.rb
Constant Summary
Constants included from Helpers
Helpers::ELEMENTS, Helpers::L, Helpers::PERIODS
Instance Attribute Summary collapse
-
#atomic_number ⇒ Object
readonly
Returns the value of attribute atomic_number.
-
#charge ⇒ Object
readonly
Returns the value of attribute charge.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#is_nobel_gas ⇒ Object
readonly
Returns the value of attribute is_nobel_gas.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#period ⇒ Object
readonly
Returns the value of attribute period.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
- #compressed_electron_configuration ⇒ Object
- #electron_configuration(sorted: true) ⇒ Object
- #human_friendly_c_e_c ⇒ Object
-
#initialize(opts) ⇒ Element
constructor
A new instance of Element.
- #to_s ⇒ Object
Methods included from Helpers
#get_c_e_c, #get_e_c, #get_group, #get_name
Constructor Details
#initialize(opts) ⇒ Element
Returns a new instance of Element.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/little_elementor.rb', line 9 def initialize(opts) opts = opts.has_key?(:charge) ? opts : opts.merge({:charge => 0}) @charge = opts[:charge] if opts.has_key?(:atomic_number) @atomic_number = opts[:atomic_number] + @charge @symbol = LittleElementor::Helpers::ELEMENTS[@atomic_number-1][:sym] elsif opts.has_key?(:symbol) @atomic_number = LittleElementor::Helpers::ELEMENTS.find_index{|i| i[:sym] == opts[:symbol]} + 1 @symbol = opts[:symbol] end @group = @atomic_number == 2 ? 18 : get_group() @is_nobel_gas = @group == 18 @name = get_name() @period = electron_configuration.map(&:n).max end |
Instance Attribute Details
#atomic_number ⇒ Object (readonly)
Returns the value of attribute atomic_number.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def atomic_number @atomic_number end |
#charge ⇒ Object (readonly)
Returns the value of attribute charge.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def charge @charge end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def group @group end |
#is_nobel_gas ⇒ Object (readonly)
Returns the value of attribute is_nobel_gas.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def is_nobel_gas @is_nobel_gas end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def name @name end |
#period ⇒ Object (readonly)
Returns the value of attribute period.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def period @period end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def symbol @symbol end |
Instance Method Details
#compressed_electron_configuration ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/little_elementor.rb', line 33 def compressed_electron_configuration if @compressed_electron_configuration @compressed_electron_configuration else @compressed_electron_configuration = get_c_e_c() end end |
#electron_configuration(sorted: true) ⇒ Object
25 26 27 |
# File 'lib/little_elementor.rb', line 25 def electron_configuration(sorted: true) get_e_c(sorted) end |
#human_friendly_c_e_c ⇒ Object
41 42 43 44 |
# File 'lib/little_elementor.rb', line 41 def human_friendly_c_e_c sym = @period == 1 ? "" : "[#{compressed_electron_configuration[0].symbol}] " "#{sym}#{compressed_electron_configuration[1].map(&:to_s).join ", "}" end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/little_elementor.rb', line 29 def to_s "Compressed Electron Configuration: #{human_friendly_c_e_c}\nSymbol: #{@symbol}\nis a noble gas?: #{@is_nobel_gas}\ncharge: #{@charge}\nname: #{@name}\natomic_number #{@atomic_number}\nsorted electron configuration: #{electron_configuration.map(&:to_s)}\nelectron configuration: #{electron_configuration(sorted: false).map(&:to_s)}\nperiod: #{@period}\ngroup: #{@group}" end |