Class: LittleElementor::Element

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/little_elementor.rb

Constant Summary

Constants included from Helpers

Helpers::ELEMENTS, Helpers::L

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#get_e_c, #get_group

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_numberObject (readonly)

Returns the value of attribute atomic_number.



8
9
10
# File 'lib/little_elementor.rb', line 8

def atomic_number
  @atomic_number
end

#chargeObject (readonly)

Returns the value of attribute charge.



8
9
10
# File 'lib/little_elementor.rb', line 8

def charge
  @charge
end

#groupObject (readonly)

Returns the value of attribute group.



8
9
10
# File 'lib/little_elementor.rb', line 8

def group
  @group
end

#is_nobel_gasObject (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

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/little_elementor.rb', line 8

def name
  @name
end

#periodObject (readonly)

Returns the value of attribute period.



8
9
10
# File 'lib/little_elementor.rb', line 8

def period
  @period
end

#symbolObject (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_sObject



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