Class: EpnApi::Paper

Inherits:
Object
  • Object
show all
Defined in:
lib/epn_api/paper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Paper

Returns a new instance of Paper.



6
7
8
9
10
11
12
13
14
# File 'lib/epn_api/paper.rb', line 6

def initialize(args)
  self.grade = args[:grade] or raise "Paper needs Grade"
  self.recycledcontent = args[:recycled_percent] or raise "Paper needs Recycled Percent"
  self.name = args[:name] || get_name( args[:grade] )
  self.annualqp= {"amount" => 100000, "qpunits" => "pounds"}
  %w(trees water energy solid_waste greenhouse_gas).each do |column|
    self.send("#{column}=", args[column.to_sym]) if args[column.to_sym]
  end   
end

Instance Attribute Details

#annualqpObject

Returns the value of attribute annualqp.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def annualqp
  @annualqp
end

#energyObject

Returns the value of attribute energy.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def energy
  @energy
end

#gradeObject

Returns the value of attribute grade.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def grade
  @grade
end

#greenhouse_gasObject

Returns the value of attribute greenhouse_gas.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def greenhouse_gas
  @greenhouse_gas
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def name
  @name
end

#recycledcontentObject

Returns the value of attribute recycledcontent.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def recycledcontent
  @recycledcontent
end

#solid_wasteObject

Returns the value of attribute solid_waste.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def solid_waste
  @solid_waste
end

#treesObject

Returns the value of attribute trees.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def trees
  @trees
end

#waterObject

Returns the value of attribute water.



4
5
6
# File 'lib/epn_api/paper.rb', line 4

def water
  @water
end

Instance Method Details

#get_name(grade) ⇒ Object



16
17
18
19
# File 'lib/epn_api/paper.rb', line 16

def get_name(grade)
  paper_name_hash = self.initialize_paper_hash
  paper_name_hash[grade]
end

#initialize_paper_hashObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/epn_api/paper.rb', line 21

def initialize_paper_hash
  paper_name_hash = {
    1  =>  "Uncoated Freesheet (e.g. copy paper)"        ,
    2  =>  "Coated Freesheet (e.g. high-end catalog)"    ,
    3  =>  "Uncoated Groundwood (e.g. newsprint)"        ,
    4  =>  "Coated Groundwood (e.g. catalog, magazine)"  ,
    5  =>  "Supercalendered (e.g. newspaper inserts)"    ,
    6  =>  "Corrugated: Unbleached"                      ,
    7  =>  "Corrugated: Semi-bleached"                   ,
    8  =>  "Corrugated: Bleached"                        ,
    9  =>  "Paperboard: Solid Bleached Sulfate (SBS)"    ,
    10 =>  "Paperboard: Coated Unbleached Kraft (CUK)"   ,
    11 =>  "Paperboard: Uncoated Bleached Kraft"         ,
    12 =>  "Paperboard: Uncoated Unbleached Kraft"       ,
    13 =>  "Paperboard: Coated Recycled Board (CRB)"     ,
  }
end

#to_return_hashObject



71
72
73
74
75
76
77
# File 'lib/epn_api/paper.rb', line 71

def to_return_hash
  return_hash = Hash.new
  %w(grade recycledcontent name trees water energy solid_waste greenhouse_gas).each do |key|
    return_hash.store( key, self.send("#{key}"))
  end
  return return_hash
end

#unit_checkObject



39
40
41
42
# File 'lib/epn_api/paper.rb', line 39

def unit_check
  raise "incorrect units" if self.annualqp != {"amount" => 100000, "qpunits" => "pounds"}
  return self.annualqp["amount"]
end

#update_via_epnObject

PUSH THIS PROCESS TO THE APP FROM THE WRAPPER, LET RAILS COMPARE def compare(existing_paper)

new_paper_string = self.object_id_strip_from_string
existing_paper_string = existing_paper.object_id_strip_from_string
if (new_paper_string == existing_paper_string)
  return false
else
  return self
end

end



65
66
67
68
69
# File 'lib/epn_api/paper.rb', line 65

def update_via_epn
  api_doc = EpnApi::ApiDoc.new
  api_doc.epn_response!( self )
  self.to_return_hash
end