Class: EnvImpact

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/EnvImpact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, pr_g, ch_g, lp_g, gei, terrain) ⇒ EnvImpact

Returns a new instance of EnvImpact.



10
11
12
13
14
# File 'lib/EnvImpact.rb', line 10

def initialize(name, pr_g, ch_g, lp_g , gei, terrain)
    @name = name
    @pr_g, @ch_g, @lp_g  = pr_g, ch_g, lp_g  
    @gei, @terrain = gei, terrain
end

Instance Attribute Details

#ch_gObject

Returns the value of attribute ch_g.



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

def ch_g
  @ch_g
end

#geiObject

Returns the value of attribute gei.



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

def gei
  @gei
end

#lp_gObject

Returns the value of attribute lp_g.



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

def lp_g
  @lp_g
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pr_gObject

Returns the value of attribute pr_g.



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

def pr_g
  @pr_g
end

#terrainObject

Returns the value of attribute terrain.



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

def terrain
  @terrain
end

Instance Method Details

#<=>(other) ⇒ Object



28
29
30
31
32
# File 'lib/EnvImpact.rb', line 28

def <=>(other)
    return nil unless other.instance_of? EnvImpact
    
    n_value + e_value <=> other.n_value + other.e_value
end

#e_valueObject



24
25
26
# File 'lib/EnvImpact.rb', line 24

def e_value
    (gei + terrain) 
end

#n_valueObject



20
21
22
# File 'lib/EnvImpact.rb', line 20

def n_value
    (@pr_g*4 + @ch_g*4 + lp_g*9) 
end

#to_sObject



16
17
18
# File 'lib/EnvImpact.rb', line 16

def to_s
    "#{name} =>| Proteinas/g: #{pr_g} | Carbohidratos/g: #{ch_g} | Lipidos/g: #{lp_g} | GEI: #{gei} | m²/año: #{terrain}"
end