Class: Species
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Species
- Defined in:
- lib/earth/pet/species.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.[](name) ⇒ Object
16 17 18 |
# File 'lib/earth/pet/species.rb', line 16 def [](name) find_by_name name.to_s end |
.marginal_dietary_requirement_fallback ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/earth/pet/species.rb', line 20 def marginal_dietary_requirement_fallback total_diet_size = thoroughly_researched.map(&:weighted_diet_size).sum 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
44 45 46 |
# File 'lib/earth/pet/species.rb', line 44 def cat? eql? self.class[:cat] end |
#diet_size ⇒ Object
30 31 32 33 |
# File 'lib/earth/pet/species.rb', line 30 def diet_size return unless weight and marginal_dietary_requirement and fixed_dietary_requirement weight * marginal_dietary_requirement + fixed_dietary_requirement end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/earth/pet/species.rb', line 40 def to_s name end |
#weighted_diet_size ⇒ Object
35 36 37 38 |
# File 'lib/earth/pet/species.rb', line 35 def weighted_diet_size return unless _diet_size = diet_size and _population = population _diet_size * _population end |