Sha256: 6b1c8b552bac23159fe3e4a4c6cf239eb29ceeeab02d0f16bfa52024510a7fae

Contents?: true

Size: 1.47 KB

Versions: 38

Compression:

Stored size: 1.47 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'
  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

38 entries across 38 versions & 2 rubygems

Version Path
earth-0.2.6 lib/earth/air/airport.rb
earth-0.2.5 lib/earth/air/airport.rb
earth-0.2.4 lib/earth/air/airport.rb
earth-ruby19-0.2.3 lib/earth/air/airport.rb
earth-0.2.3 lib/earth/air/airport.rb
earth-0.2.2 lib/earth/air/airport.rb
earth-0.2.1 lib/earth/air/airport.rb
earth-0.2.0 lib/earth/air/airport.rb
earth-0.1.4 lib/earth/air/airport.rb
earth-0.1.3 lib/earth/air/airport.rb
earth-0.1.2 lib/earth/air/airport.rb
earth-0.1.1 lib/earth/air/airport.rb
earth-0.1.0 lib/earth/air/airport.rb
earth-0.0.43 lib/earth/air/airport.rb
earth-0.0.42 lib/earth/air/airport.rb
earth-0.0.41 lib/earth/air/airport.rb
earth-0.0.40 lib/earth/air/airport.rb
earth-0.0.39 lib/earth/air/airport.rb
earth-0.0.38 lib/earth/air/airport.rb
earth-0.0.37 lib/earth/air/airport.rb