Class: Species

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/earth/pet/species.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](name) ⇒ Object



29
30
31
# File 'lib/earth/pet/species.rb', line 29

def [](name)
  find_by_name name.to_s
end

.marginal_dietary_requirement_fallbackObject



33
34
35
36
37
38
39
40
# File 'lib/earth/pet/species.rb', line 33

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

Returns:

  • (Boolean)


57
58
59
# File 'lib/earth/pet/species.rb', line 57

def cat?
  eql? self.class[:cat]
end

#diet_sizeObject



43
44
45
46
# File 'lib/earth/pet/species.rb', line 43

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_sObject



53
54
55
# File 'lib/earth/pet/species.rb', line 53

def to_s
  name
end

#weighted_diet_sizeObject



48
49
50
51
# File 'lib/earth/pet/species.rb', line 48

def weighted_diet_size
  return unless _diet_size = diet_size and _population = population
  _diet_size.to_f * _population
end