class Planefinder::AirplaneListing

Contains an airplane listing, including contact info, total engine time, etc.

Constants

PREFERRED_PROPERTY_ORDER

Attributes

properties[R]

Public Class Methods

new(listing_hash) click to toggle source
# File lib/planefinder/airplane_listing.rb, line 9
def initialize(listing_hash)
  # replace empty strings with nil
  @properties = listing_hash.inject({}) do |h, (k,v)|
    v == "" ? h[k] = nil : h[k] = v
    h
  end
  define_attributes(@properties)
end

Public Instance Methods

[](property_name) click to toggle source
# File lib/planefinder/airplane_listing.rb, line 59
def [](property_name)
  property_name = property_name.to_s if property_name.class == Symbol
  @properties[property_name]
end
define_attributes(hash) click to toggle source
# File lib/planefinder/airplane_listing.rb, line 24
def define_attributes(hash)
  hash.each do |k, v|
    next if instance_variable_defined?("@#{k}") || self.class.method_defined?(k.to_sym)
    metaclass.send :attr_reader, k
    instance_variable_set("@#{k}".to_sym, v)
  end
end
location() click to toggle source
# File lib/planefinder/airplane_listing.rb, line 32
def location
  Geokit::Geocoders::AirplaneGeocoder.geocode(location_text) if location_type
end
location_description() click to toggle source
# File lib/planefinder/airplane_listing.rb, line 55
def location_description
  location_type + ": " + location_text
end
location_text() click to toggle source
# File lib/planefinder/airplane_listing.rb, line 49
def location_text
  # the type might be a "city, state", but otherwise treat it like a single value
  types = location_type.split(", ")
  types.length == 1 ? @properties[types[0]] :  "#{@properties[types[0]]}, #{@properties[types[1]]}"
end
location_type() click to toggle source
# File lib/planefinder/airplane_listing.rb, line 36
def location_type
  PREFERRED_PROPERTY_ORDER.each do |p|
    if p =~ /city/
      city = p
      state = p.gsub('city', 'state')
      return "#{city}, #{state}" if @properties[city] and @properties[state]
    else
      return p if @properties[p]
    end
  end
  nil
end
metaclass() click to toggle source
# File lib/planefinder/airplane_listing.rb, line 18
def metaclass
  class << self
    self
  end
end
to_s() click to toggle source
# File lib/planefinder/airplane_listing.rb, line 64
def to_s
  @properties.inspect
end