Class: NacoInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/nacofetch/naco_interface.rb

Instance Method Summary collapse

Constructor Details

#initializeNacoInterface

Returns a new instance of NacoInterface.



12
13
14
# File 'lib/nacofetch/naco_interface.rb', line 12

def initialize
  @base_url = "http://aeronav.faa.gov"
end

Instance Method Details

#current_cycleObject



38
39
40
# File 'lib/nacofetch/naco_interface.rb', line 38

def current_cycle
  self.cycles.select { |cycle| cycle.status == "CURRENT" }.first
end

#cyclesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nacofetch/naco_interface.rb', line 16

def cycles
  unless @cycles_var
    url = "/index.asp?xml=aeronav/applications/d_tpp"
    doc = Nokogiri::HTML(open(@base_url + url))
    @cycles_var = []

    tables = doc.xpath('//table[@title="Digital Terminal Procedures Publication"]')

    tables.xpath('//td[@headers="header1"]').each do |cycle|
      url = cycle.xpath('./a/@href').to_s()
      @cycles_var << Cycle.new(
          url.sub(/digital_tpp/, "digital_tpp_search"), # todo: there's gotta be a less hacky way to do this'
          /ver=(\d+)/.match(url)[1],
          string_to_time(/eff=(\d+-\d+-\d+)/.match(url)[1], '%m-%d-%Y'),
          string_to_time(/end=(\d+-\d+-\d+)/.match(url)[1], '%m-%d-%Y')
      )
    end
  end

  @cycles_var
end

#fetch_plates_for_airport(metafile_url, ident) ⇒ Object



51
52
53
54
55
56
# File 'lib/nacofetch/naco_interface.rb', line 51

def fetch_plates_for_airport(metafile_url, ident)
  xpath = "/digital_tpp/state_code/city_name/airport_name[@icao_ident = '#{ident}' or @apt_ident = '#{ident}']"
  #xpath = "/digital_tpp/state_code[@ID = 'GA']"

  fetch_plates_for_xpath(metafile_url, xpath)
end

#fetch_plates_for_state(metafile_url, statecode) ⇒ Object



58
59
60
61
62
# File 'lib/nacofetch/naco_interface.rb', line 58

def fetch_plates_for_state(metafile_url, statecode)
  xpath = "/digital_tpp/state_code[@ID = '#{statecode}']"

  fetch_plates_for_xpath(metafile_url, xpath)
end

#fetch_plates_for_volume(metafile_url, volumecode) ⇒ Object



64
65
66
67
68
# File 'lib/nacofetch/naco_interface.rb', line 64

def fetch_plates_for_volume(metafile_url, volumecode)
  xpath = "/digital_tpp/state_code[city_name/@volume = '#{volumecode}']"

  fetch_plates_for_xpath(metafile_url, xpath)
end

#metafile_for_cycle(cycle) ⇒ Object



46
47
48
49
# File 'lib/nacofetch/naco_interface.rb', line 46

def metafile_for_cycle(cycle)
  fetch_metafile(cycle) unless File.exists?(metafilename(cycle))
  metafilename(cycle)
end

#pending_cycleObject



42
43
44
# File 'lib/nacofetch/naco_interface.rb', line 42

def pending_cycle
  self.cycles.select { |cycle| cycle.status == "PENDING" }.first
end