Sha256: 9365e36751a9bdf8f641a8fcd2d5de6f1a51c3af03474123c20124b649ae1382

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

class ResidenceFuelType < ActiveRecord::Base
  set_primary_key :name
  
  has_many :prices, :class_name => 'ResidenceFuelPrice', :foreign_key => 'residence_fuel_type_name'
  
  col :name
  col :emission_factor, :type => :float
  col :emission_factor_units
  # col :energy_content, :type => :float
  # col :energy_content_units
  
  def price_per_unit(relaxations = [])
    conditions = { :residence_fuel_type_name => self }
    relaxations.push Hash.new
    relaxations.grab do |relaxation|
      relaxation_conditions = Hash.new
      if timeframe = relaxation[:timeframe]
        relaxation_conditions[:year] = timeframe.from.year
        relaxation_conditions[:month] = timeframe.from.month..timeframe.to.yesterday.month
      end
      if location = relaxation[:location]
        relaxation_conditions[:locatable_type] = location.class.to_s
        relaxation_conditions[:locatable_id] = location.id
      end
      ResidenceFuelPrice.average :price, :conditions => conditions.merge(relaxation_conditions)
    end
  end

  class << self
    def [](fuel)
      find_by_name fuel.to_s.humanize.downcase
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
earth-0.11.0 lib/earth/residence/residence_fuel_type.rb
earth-0.7.0 lib/earth/residence/residence_fuel_type.rb
earth-0.6.6 lib/earth/residence/residence_fuel_type.rb
earth-0.6.5 lib/earth/residence/residence_fuel_type.rb
earth-0.6.4 lib/earth/residence/residence_fuel_type.rb
earth-0.6.3 lib/earth/residence/residence_fuel_type.rb
earth-0.6.2 lib/earth/residence/residence_fuel_type.rb
earth-0.6.1 lib/earth/residence/residence_fuel_type.rb
earth-0.6.0 lib/earth/residence/residence_fuel_type.rb