Sha256: dc65e28c3a8bc63484b58f306f2f937c6115c9b35b27ed69a5bd5d5b75b6d503

Contents?: true

Size: 1.04 KB

Versions: 52

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

52 entries across 52 versions & 2 rubygems

Version Path
earth-0.5.0 lib/earth/residence/residence_fuel_type.rb
earth-0.4.12 lib/earth/residence/residence_fuel_type.rb
earth-0.4.11 lib/earth/residence/residence_fuel_type.rb
earth-0.4.10 lib/earth/residence/residence_fuel_type.rb
earth-0.4.9 lib/earth/residence/residence_fuel_type.rb
earth-0.4.8 lib/earth/residence/residence_fuel_type.rb
earth-0.4.7 lib/earth/residence/residence_fuel_type.rb
earth-0.4.6 lib/earth/residence/residence_fuel_type.rb
earth-0.4.5 lib/earth/residence/residence_fuel_type.rb
earth-0.4.4 lib/earth/residence/residence_fuel_type.rb
earth-0.4.3 lib/earth/residence/residence_fuel_type.rb
earth-0.4.2 lib/earth/residence/residence_fuel_type.rb
earth-0.4.1 lib/earth/residence/residence_fuel_type.rb
earth-0.4.0 lib/earth/residence/residence_fuel_type.rb
earth-0.3.15 lib/earth/residence/residence_fuel_type.rb
earth-0.3.14 lib/earth/residence/residence_fuel_type.rb
earth-0.3.13 lib/earth/residence/residence_fuel_type.rb
earth-0.3.11 lib/earth/residence/residence_fuel_type.rb
earth-0.3.10 lib/earth/residence/residence_fuel_type.rb
earth-0.3.9 lib/earth/residence/residence_fuel_type.rb