Class: Species
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Species
show all
- Extended by:
- Earth::Model
- Defined in:
- lib/earth/pet/species.rb
Constant Summary
collapse
- TABLE_STRUCTURE =
<<-EOS
CREATE TABLE species
(
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
population INTEGER,
diet_emission_intensity FLOAT,
diet_emission_intensity_units CHARACTER VARYING(255),
weight FLOAT,
weight_units CHARACTER VARYING(255),
marginal_dietary_requirement FLOAT,
marginal_dietary_requirement_units CHARACTER VARYING(255),
fixed_dietary_requirement FLOAT,
fixed_dietary_requirement_units CHARACTER VARYING(255),
minimum_weight FLOAT,
minimum_weight_units CHARACTER VARYING(255),
maximum_weight FLOAT,
maximum_weight_units CHARACTER VARYING(255)
);
EOS
Class Method Summary
collapse
Instance Method Summary
collapse
extend_mining, extended, registry
Class Method Details
.[](name) ⇒ Object
43
44
45
|
# File 'lib/earth/pet/species.rb', line 43
def [](name)
find_by_name name.to_s
end
|
.marginal_dietary_requirement_fallback ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/earth/pet/species.rb', line 47
def marginal_dietary_requirement_fallback
total_diet_size = thoroughly_researched.map(&:weighted_diet_size).sum.to_f
total_population = thoroughly_researched.sum(:population)
return 0.0 unless total_population > 0.0
average_weight = thoroughly_researched.weighted_average(:weight, :weighted_by => :population)
return 0.0 unless average_weight > 0.0
(total_diet_size / total_population) / average_weight
end
|
Instance Method Details
#cat? ⇒ Boolean
71
72
73
|
# File 'lib/earth/pet/species.rb', line 71
def cat?
eql? self.class[:cat]
end
|
#diet_size ⇒ Object
57
58
59
60
|
# File 'lib/earth/pet/species.rb', line 57
def diet_size
return unless weight and marginal_dietary_requirement and fixed_dietary_requirement
weight.to_f * marginal_dietary_requirement + fixed_dietary_requirement
end
|
#to_s ⇒ Object
67
68
69
|
# File 'lib/earth/pet/species.rb', line 67
def to_s
name
end
|
#weighted_diet_size ⇒ Object
62
63
64
65
|
# File 'lib/earth/pet/species.rb', line 62
def weighted_diet_size
return unless _diet_size = diet_size and _population = population
_diet_size.to_f * _population
end
|