Class: Ilm::Chemistry::Substance

Inherits:
Object
  • Object
show all
Defined in:
lib/ilm/chemistry/substance.rb

Overview

This class is for mixture of compounds/elements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Substance

Returns a new instance of Substance.



6
7
8
9
10
11
12
13
14
15
# File 'lib/ilm/chemistry/substance.rb', line 6

def initialize(args)
  @species = {}
  tt_wt_p = args.inject(0) { |sum, arg| sum + arg.last }
  args.each do |specie, wt_p|
    @species.merge! specie => {
      compound: Compound.new(specie),
      weight_percent: wt_p.to_f / tt_wt_p * 100
    }
  end
end

Instance Attribute Details

#speciesObject

Returns the value of attribute species.



5
6
7
# File 'lib/ilm/chemistry/substance.rb', line 5

def species
  @species
end