class PLA

Public Class Methods

all() click to toggle source
# File lib/pla.rb, line 18
def self.all
  [
    self.arrivals,
    self.departures,
    self.in_port
  ].flatten.uniq
end
arrivals() click to toggle source
# File lib/pla.rb, line 6
def self.arrivals
  PLA::Arrivals.new.records
end
departures() click to toggle source
# File lib/pla.rb, line 10
def self.departures
  PLA::Departures.new.records
end
find(movement_type, field, key) click to toggle source
# File lib/pla.rb, line 26
def self.find movement_type, field, key
  if self.methods.include? movement_type
    movements = self.send(movement_type)

    if field == :location
      return [
        self.munge_by_field(movements, :select, :to, key),
        self.munge_by_field(movements, :select, :from, key)
      ].flatten.uniq
    else
      return self.munge_by_field movements, :select, field, key
    end
  end
  []
end
in_port() click to toggle source
# File lib/pla.rb, line 14
def self.in_port
  PLA::InPort.new.records
end
method_missing(m, *args, &block) click to toggle source
Calls superclass method
# File lib/pla.rb, line 66
def self.method_missing(m, *args, &block)
  if m.to_s =~ /^(find|sort)_(.*)_by_(.*)$/
    querier = $1
    type = $2.to_sym
    field = $3.to_sym

    if querier == 'find'
      return self.find(type, field, args.first)
    elsif querier == 'sort'
      return self.sort(type, field)
    end
  end
  super
end
munge_by_field(movements, method, field, search_value=nil) click to toggle source
# File lib/pla.rb, line 50
def self.munge_by_field movements, method, field, search_value=nil
  if field =~ /^(.*)_(.*)$/
    field = $1
    field_key = $2

    search_value.nil? ?
      movements.send(method){|m| m[field.to_sym][field_key.to_sym]} :
      movements.send(method){|m| m[field.to_sym][field_key.to_sym] == search_value}

  else
    search_value.nil? ?
      movements.send(method){|m| m[field.to_sym]} :
      movements.send(method){|m| m[field.to_sym] == search_value}
  end
end
respond_to?(method_sym, include_private = false) click to toggle source
Calls superclass method
# File lib/pla.rb, line 81
def self.respond_to?(method_sym, include_private = false)
  if method_sym.to_s =~ /^(find|sort)_(.*)_by_(.*)$/ and
    self.methods.include? $2.to_sym
    true
  else
    super
  end
end
sort(movement_type, field) click to toggle source
# File lib/pla.rb, line 42
def self.sort movement_type, field
  if self.methods.include? movement_type
    movements = self.send(movement_type)
    return self.munge_by_field movements, :sort_by, field
  end
  []
end