Class: CO2Equivalents::ResultSet

Inherits:
Hash
  • Object
show all
Defined in:
lib/co2_equivalents/result_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kgs_co2, *args) ⇒ ResultSet

Returns a new instance of ResultSet.



11
12
13
14
# File 'lib/co2_equivalents/result_set.rb', line 11

def initialize(kgs_co2, *args)
  self.kgs_co2 = kgs_co2
  self.constraints = args
end

Instance Attribute Details

#constraintsObject

Returns the value of attribute constraints.



9
10
11
# File 'lib/co2_equivalents/result_set.rb', line 9

def constraints
  @constraints
end

#kgs_co2Object

Returns the value of attribute kgs_co2.



9
10
11
# File 'lib/co2_equivalents/result_set.rb', line 9

def kgs_co2
  @kgs_co2
end

Class Method Details

.compute(kgs_co2, *args) ⇒ Object



3
4
5
6
7
# File 'lib/co2_equivalents/result_set.rb', line 3

def self.compute(kgs_co2, *args)
  set = new kgs_co2, *args
  set.compute
  set
end

Instance Method Details

#computeObject



16
17
18
19
20
21
22
# File 'lib/co2_equivalents/result_set.rb', line 16

def compute
  CO2Equivalents.groups.each do |group|
    group.equivalences.each do |name, equivalent|
      self[name] = kgs_co2.to_f * equivalent.factor
    end
  end
end