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.
-
#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(atomic_number, charge = 0) ⇒ Element
constructor
A new instance of Element.
- #to_s ⇒ Object
Methods included from Helpers
Constructor Details
#initialize(atomic_number, charge = 0) ⇒ Element
Returns a new instance of Element.
9 10 11 12 13 14 15 16 17 |
# File 'lib/little_elementor.rb', line 9 def initialize(atomic_number, charge = 0) @atomic_number = atomic_number + charge @is_nobel_gas = [2, 10, 18, 36, 54, 86, 118].include?(@atomic_number) @name = LittleElementor::Helpers::ELEMENTS[@atomic_number-1][:name] @period = electron_configuration.map(&:n).max @charge = charge @group = get_group() @symbol = LittleElementor::Helpers::ELEMENTS[@atomic_number-1][:sym] 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
#electron_configuration(sorted: true) ⇒ Object
19 20 21 |
# File 'lib/little_elementor.rb', line 19 def electron_configuration(sorted: true) get_e_c(sorted) end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/little_elementor.rb', line 23 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}" end |