Class: AIPP::AIP Abstract

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Patcher
Defined in:
lib/aipp/aip.rb

Overview

This class is abstract.

Constant Summary collapse

DEPENDS =
[]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Patcher

#attach_patches, #detach_patches

Constructor Details

#initialize(aip:, downloader:, fixture:, parser:) ⇒ AIP

Returns a new instance of AIP.



31
32
33
34
# File 'lib/aipp/aip.rb', line 31

def initialize(aip:, downloader:, fixture:, parser:)
  @aip, @downloader, @fixture, @parser = aip, downloader, fixture, parser
  self.class.include ("AIPP::%s::Helpers::URL" % options[:region]).constantize
end

Instance Attribute Details

#aipString (readonly)

Returns AIP name (e.g. “ENR-2.1”).

Returns:

  • (String)

    AIP name (e.g. “ENR-2.1”)



11
12
13
# File 'lib/aipp/aip.rb', line 11

def aip
  @aip
end

#fixtureObject (readonly)

Returns Fixture read from YAML file.

Returns:

  • (Object)

    Fixture read from YAML file



14
15
16
# File 'lib/aipp/aip.rb', line 14

def fixture
  @fixture
end

Instance Method Details

#add(feature) ⇒ Object

Add feature to AIXM

Parameters:

  • feature (AIXM::Feature)

    e.g. airport or airspace



56
57
58
59
# File 'lib/aipp/aip.rb', line 56

def add(feature)
  verbose_info "Adding #{feature.inspect}"
  aixm.features << feature
end

#bordersObject

See Also:



28
# File 'lib/aipp/aip.rb', line 28

def_delegators :@parser, :aixm, :config, :options, :borders, :cache

#cacheObject

See Also:



28
# File 'lib/aipp/aip.rb', line 28

def_delegators :@parser, :aixm, :config, :options, :borders, :cache

#closeObject

See Also:

  • Downloader#close


18
# File 'lib/aipp/aip.rb', line 18

def_delegator :@downloader, :close

#configObject

See Also:



28
# File 'lib/aipp/aip.rb', line 28

def_delegators :@parser, :aixm, :config, :options, :borders, :cache

#optionsObject

See Also:



28
# File 'lib/aipp/aip.rb', line 28

def_delegators :@parser, :aixm, :config, :options, :borders, :cache

#read(aip_file = nil) ⇒ Nokogiri::HTML5::Document, String

Read an AIP source file

Depending on whether a local copy of the file exists, either:

  • download from URL to local storage and read from local archive

  • read from local archive

An URL builder method url_for(aip_file) must be defined either in helper.rb or in the AIP parser definition (e.g. ENR-2.1.rb).

Parameters:

  • aip_file (String) (defaults to: nil)

    e.g. “ENR-2.1” or “AD-2.LFMV” (default: aip)

Returns:

  • (Nokogiri::HTML5::Document, String)

    HTML as Nokogiri document, PDF or TXT as String



48
49
50
51
# File 'lib/aipp/aip.rb', line 48

def read(aip_file=nil)
  aip_file ||= aip
  @downloader.read(document: aip_file, url: url_for(aip_file))
end

#select(klass, attributes = {}) ⇒ Array<AIXM::Feature>

Search features previously written to AIXM and return those matching the given class and attribute values

Examples:

select(:airport, id: "LFNT")

Parameters:

  • klass (Class, Symbol)

    feature class like AIXM::Feature::Airport or AIXM::Feature::NavigationalAid::VOR, shorthand notations as symbols e.g. :airport or :vor as listed in AIXM::CLASSES are recognized as well

  • attributes (Hash) (defaults to: {})

    filter by these attributes and their values

Returns:

  • (Array<AIXM::Feature>)


72
73
74
75
76
77
78
79
80
81
# File 'lib/aipp/aip.rb', line 72

def select(klass, attributes={})
  klass = AIXM::CLASSES.fetch(klass) if klass.is_a? Symbol
  aixm.features.select do |feature|
    if feature.is_a? klass
      attributes.reduce(true) do |memo, (attribute, value)|
        memo && feature.send(attribute) == value
      end
    end
  end
end