class Species

Constants

TABLE_STRUCTURE

Public Class Methods

[](name) click to toggle source
# File lib/earth/pet/species.rb, line 43
def [](name)
  find_by_name name.to_s
end
marginal_dietary_requirement_fallback() click to toggle source
# 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

Public Instance Methods

cat?() click to toggle source
# File lib/earth/pet/species.rb, line 71
def cat?
  eql? self.class[:cat]
end
diet_size() click to toggle source
# 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() click to toggle source
# File lib/earth/pet/species.rb, line 67
def to_s
  name
end
weighted_diet_size() click to toggle source
# 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