Class: Alumina::Element

Inherits:
Object show all
Defined in:
lib/alumina/element.rb

Overview

Each of the elements has a singleton instance of this class. You do not create instances of this class; they are loaded from a data file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atomic_number, name, symbol) ⇒ Element

Returns a new instance of Element.



15
16
17
18
19
# File 'lib/alumina/element.rb', line 15

def initialize(atomic_number, name, symbol)
  @atomic_number = atomic_number
  @name = name
  @symbol = symbol
end

Instance Attribute Details

#atomic_numberFixnum (readonly)

Returns The element’s atomic number (hydrogen is 1).

Returns:

  • (Fixnum)

    The element’s atomic number (hydrogen is 1).



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

def atomic_number
  @atomic_number
end

#nameString (readonly)

Returns The element’s name.

Returns:

  • (String)

    The element’s name.



10
11
12
# File 'lib/alumina/element.rb', line 10

def name
  @name
end

#symbolString (readonly)

Returns The element’s symbol (hydrogen is @H@).

Returns:

  • (String)

    The element’s symbol (hydrogen is @H@).



12
13
14
# File 'lib/alumina/element.rb', line 12

def symbol
  @symbol
end

Instance Method Details

#<=>(other) ⇒ -1, ...

Provides a natural ordering based on atomic number.

Parameters:

  • other (Element)

    The other element to compare against.

Returns:

  • (-1, 0, 1)

    The sort equivalency.



26
27
28
# File 'lib/alumina/element.rb', line 26

def <=>(other)
  atomic_number <=> other.atomic_number
end