Sha256: 7a860282df363ea816c4bbb839868812128362d4247b2ce8e7127d8677201e68

Contents?: true

Size: 1.31 KB

Versions: 49

Compression:

Stored size: 1.31 KB

Contents

class Species < ActiveRecord::Base
  set_primary_key :name
  
  has_many :pets
  
  scope :thoroughly_researched, :conditions => 'marginal_dietary_requirement IS NOT NULL'
  
  falls_back_on :diet_emission_intensity => lambda { weighted_average :diet_emission_intensity, :weighted_by => :population }, # kg CO2 / joule
                :marginal_dietary_requirement => lambda { (thoroughly_researched.map(&:weighted_diet_size).sum / thoroughly_researched.sum(:population) ) / thoroughly_researched.weighted_average(:weight, :weighted_by => :population)}, # joules
                :fixed_dietary_requirement => 0, # force a zero intercept to be respectful of our tiny tiny animal friends
                :weight => lambda { weighted_average :weight, :weighted_by => :population } # kg

  data_miner do
    tap "Brighter Planet's species data", Earth.taps_server
  end
  
  class << self
    def [](name)
      find_by_name name.to_s
    end
  end
  
  def diet_size
    return unless weight and marginal_dietary_requirement and fixed_dietary_requirement
    weight * marginal_dietary_requirement + fixed_dietary_requirement
  end
  
  def weighted_diet_size
    return unless _diet_size = diet_size and _population = population
    _diet_size * _population
  end
  
  def to_s
    name
  end
  
  def cat?
    eql? self.class[:cat]
  end
end

Version data entries

49 entries across 49 versions & 2 rubygems

Version Path
earth-0.3.3 lib/earth/pet/species.rb
earth-0.3.2 lib/earth/pet/species.rb
earth-0.3.1 lib/earth/pet/species.rb
earth-0.3.0 lib/earth/pet/species.rb
earth-0.2.14 lib/earth/pet/species.rb
earth-0.2.13 lib/earth/pet/species.rb
earth-0.2.12 lib/earth/pet/species.rb
earth-0.2.11 lib/earth/pet/species.rb
earth-0.2.9 lib/earth/pet/species.rb
earth-0.2.8 lib/earth/pet/species.rb
earth-0.2.7 lib/earth/pet/species.rb
earth-0.2.6 lib/earth/pet/species.rb
earth-0.2.5 lib/earth/pet/species.rb
earth-0.2.4 lib/earth/pet/species.rb
earth-ruby19-0.2.3 lib/earth/pet/species.rb
earth-0.2.3 lib/earth/pet/species.rb
earth-0.2.2 lib/earth/pet/species.rb
earth-0.2.1 lib/earth/pet/species.rb
earth-0.2.0 lib/earth/pet/species.rb
earth-0.1.4 lib/earth/pet/species.rb