Sha256: b685311d99fffebca26f382ecbd3ee1b60a02ab61e8d9a8f695718f5125f5c25

Contents?: true

Size: 1.04 KB

Versions: 22

Compression:

Stored size: 1.04 KB

Contents

class ResidenceFuelType < ActiveRecord::Base
  set_primary_key :name
  
  
  has_many :prices, :class_name => 'ResidenceFuelPrice', :foreign_key => 'residence_fuel_type_name'
  
  data_miner do
    tap "Brighter Planet's residence fuel types data", Earth.taps_server
  end
  
  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

22 entries across 22 versions & 1 rubygems

Version Path
earth-0.0.40 lib/earth/residence/residence_fuel_type.rb
earth-0.0.39 lib/earth/residence/residence_fuel_type.rb
earth-0.0.38 lib/earth/residence/residence_fuel_type.rb
earth-0.0.37 lib/earth/residence/residence_fuel_type.rb
earth-0.0.36 lib/earth/residence/residence_fuel_type.rb
earth-0.0.35 lib/earth/residence/residence_fuel_type.rb
earth-0.0.34 lib/earth/residence/residence_fuel_type.rb
earth-0.0.33 lib/earth/residence/residence_fuel_type.rb
earth-0.0.32 lib/earth/residence/residence_fuel_type.rb
earth-0.0.31 lib/earth/residence/residence_fuel_type.rb
earth-0.0.30 lib/earth/residence/residence_fuel_type.rb
earth-0.0.29 lib/earth/residence/residence_fuel_type.rb
earth-0.0.28 lib/earth/residence/residence_fuel_type.rb
earth-0.0.27 lib/earth/residence/residence_fuel_type.rb
earth-0.0.26 lib/earth/residence/residence_fuel_type.rb
earth-0.0.24 lib/earth/residence/residence_fuel_type.rb
earth-0.0.23 lib/earth/residence/residence_fuel_type.rb
earth-0.0.22 lib/earth/residence/residence_fuel_type.rb
earth-0.0.21 lib/earth/residence/residence_fuel_type.rb
earth-0.0.20 lib/earth/residence/residence_fuel_type.rb