Sha256: 8e607cc141537e0b9db0362db47c0ccad480eb6e772fad99e056c69189137f00

Contents?: true

Size: 1.51 KB

Versions: 35

Compression:

Stored size: 1.51 KB

Contents

class Airport < ActiveRecord::Base
  set_primary_key :iata_code
  
  # --------------------------------
  # virtual has_many association
  # has_many :segments won't work because there's no general way to specify the correct conditions
  # even if you get clever with it, like
  # has_many  :segments,
  #           :class_name => 'FlightSegment',
  #           :foreign_key => 'origin_airport_id',
  #           :conditions => 'flight_segments.destination_airport_id = #{id}'
  # you get queries like "`flight_segments`.origin_airport_id = 3654 AND (flight_segments.destination_airport_id = 3654))"
  # in which you notice the AND which must be an OR
  # and you can't just do finder_sql, because that breaks any other :select
  def segments
    FlightSegment.scoped :conditions => ['origin_airport_id = ? OR destination_airport_id = ?', id, id]
  end
  # --------------------------------
  
  belongs_to :country, :foreign_key => 'country_iso_3166_code', :primary_key => 'iso_3166_code'
  acts_as_mappable :default_units => :nms,
                   :lat_column_name => :latitude,
                   :lng_column_name => :longitude

  data_miner do
    tap "Brighter Planet's sanitized airports data", Earth.taps_server
    
    process "pull dependencies" do
      run_data_miner_on_belongs_to_associations
    end
  end
  
  def all_flights_from_here_domestic?
    !international_origin?
  end

  def all_flights_to_here_domestic?
    !international_destination?
  end
  
  def united_states?
    country == Country.united_states
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

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