Class: LittleElementor::Element
- Inherits:
-
Object
- Object
- LittleElementor::Element
- Includes:
- Helpers
- Defined in:
- lib/little_elementor.rb
Constant Summary
Constants included from Helpers
Instance Attribute Summary collapse
-
#atomic_number ⇒ Object
readonly
Returns the value of attribute atomic_number.
-
#charge ⇒ Object
readonly
Returns the value of attribute charge.
-
#fake_atomic_number ⇒ Object
readonly
Returns the value of attribute fake_atomic_number.
-
#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
- #electron_configuration(sorted: true) ⇒ Object
-
#initialize(opts) ⇒ Element
constructor
A new instance of Element.
- #to_s ⇒ Object
Methods included from Helpers
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 24 25 |
# 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) @fake_atomic_number = opts[:atomic_number] @atomic_number = @fake_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 @fake_atomic_number = @atomic_number + @charge @symbol = opts[:symbol] end @group = @atomic_number == 2 ? 18 : get_group() @is_nobel_gas = @group == 18 @name = LittleElementor::Helpers::ELEMENTS[@atomic_number-1][: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 |
#fake_atomic_number ⇒ Object (readonly)
Returns the value of attribute fake_atomic_number.
8 9 10 |
# File 'lib/little_elementor.rb', line 8 def fake_atomic_number @fake_atomic_number 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
#electron_configuration(sorted: true) ⇒ Object
27 28 29 |
# File 'lib/little_elementor.rb', line 27 def electron_configuration(sorted: true) get_e_c(sorted) end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/little_elementor.rb', line 31 def to_s "Symbol: #{@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}\nfake_atomic_number: #{@fake_atomic_number}" end |