Module: AIPP::LS::Helpers::Base

Included in:
NOTAM::ENR
Defined in:
lib/aipp/regions/LS/helpers/base.rb

Instance Method Summary collapse

Instance Method Details

#organisation_lsObject

Templates



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/aipp/regions/LS/helpers/base.rb', line 78

def organisation_ls
  unless AIPP.cache.organisation_ls
    AIPP.cache.organisation_ls = AIXM.organisation(
      source: source(position: 1, document: "GEN-3.1"),
      name: 'SWITZERLAND',
      type: 'S'
    ).tap do |organisation|
      organisation.id = 'LS'
    end
    add AIPP.cache.organisation_ls
  end
  AIPP.cache.organisation_ls
end

#origin_for(document) ⇒ Object

Mandatory Interface



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/aipp/regions/LS/helpers/base.rb', line 33

def origin_for(document)
  case document
  when 'ENR'
    variables = {
      region: 'LS',
      series: %w(W B),
      start: aixm.effective_at.beginning_of_day.to_i,
      end: aixm.expiration_at.to_i
    }
    verbose_info("Querying API with #{variables}")
    AIPP::Downloader::GraphQL.new(
      client: AIPP::NewayAPI::Client,
      query: AIPP::NewayAPI::Notam::Query,
      variables: variables
    )
  when 'AD'
    fail "not yet implemented"
  when 'AIP'
    AIPP::Downloader::HTTP.new(
      file: "https://snapshots.openflightmaps.org/live/#{AIRAC::Cycle.new.id}/ofmx/lsas/latest/isolated/ofmx_ls.xml"
    )
  when 'DABS'
    if aixm.effective_at.to_date == Time.now.utc.to_date   # DABS cross check works reliably for today only
      AIPP::Downloader::HTTP.new(
        file: "https://www.skybriefing.com/o/dabs?today",
        type: :pdf
      )
    end
  when 'shooting_grounds'
    AIPP::Downloader::HTTP.new(
      file: "https://data.geo.admin.ch/ch.vbs.schiessanzeigen/schiessanzeigen/schiessanzeigen.csv",
      type: :csv
    )
  when /^shooting_grounds-(\d+\.\d+)/
    AIPP::Downloader::HTTP.new(
      file: "https://api3.geo.admin.ch/rest/services/api/MapServer/ch.vbs.schiessanzeigen/#{$1}?sr=4326&geometryFormat=geojson",
      type: :json
    )
  else
    fail "document not recognized"
  end
end

#timetable_from(schedules) ⇒ Object

Parserettes



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/aipp/regions/LS/helpers/base.rb', line 94

def timetable_from(schedules)
  AIXM.timetable.tap do |timetable|
    schedules&.each do |schedule|
      schedule.actives.each do |actives|
        schedule.times.each do |times|
          timesheet = AIXM.timesheet(
            adjust_to_dst: false,
            dates: (actives.instance_of?(Range) ? actives : (actives..actives))
            # TODO: transform to...
            # dates: actives
          )
          timesheet.times = times
          timetable.add_timesheet timesheet
        end
      end
    end
  end
end