Class: AIPP::AIP Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Debugger, 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, included

Constructor Details

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

Returns a new instance of AIP.


36
37
38
39
# File 'lib/aipp/aip.rb', line 36

def initialize(aip:, downloader:, fixture:, parser:)
  @aip, @downloader, @fixture, @parser = aip, downloader, fixture, parser
  setup if respond_to? :setup
end

Instance Attribute Details

#aipString (readonly)

Returns AIP name (equal to the parser file name without its file extension such as “ENR-2.1” implemented in the file “ENR-2.1.rb”).

Returns:

  • (String)

    AIP name (equal to the parser file name without its file extension such as “ENR-2.1” implemented in the file “ENR-2.1.rb”)


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

def aip
  @aip
end

#aip_fileString (readonly)

Returns AIP file as passed and possibly updated by `url_for`.

Returns:

  • (String)

    AIP file as passed and possibly updated by `url_for`


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

def aip_file
  @aip_file
end

#fixtureObject (readonly)

Returns Fixture read from YAML file.

Returns:

  • (Object)

    Fixture read from YAML file


19
20
21
# File 'lib/aipp/aip.rb', line 19

def fixture
  @fixture
end

Instance Method Details

#add(feature) ⇒ AIXM::Feature

Add feature to AIXM

Parameters:

  • feature (AIXM::Feature)

    e.g. airport or airspace

Returns:

  • (AIXM::Feature)

    added feature


69
70
71
72
73
# File 'lib/aipp/aip.rb', line 69

def add(feature)
  verbose_info "adding #{feature.inspect}"
  aixm.add_feature feature
  feature
end

#bordersObject

See Also:


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

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

#cacheObject

See Also:


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

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

#closeObject

See Also:

  • Downloader#close

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

def_delegator :@downloader, :close

#configObject

See Also:


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

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

#find(object) ⇒ Object

Note:

This method is delegated to AIXM::Association::Array.

Find equal objects previously written to AIXM.


87
88
89
90
91
# File 'lib/aipp/aip.rb', line 87

%i(find_by find).each do |method|
  define_method method do |*args|
    aixm.features.send(method, *args)
  end
end

#find_by(klass, attributes = {}) ⇒ Object

Note:

This method is delegated to AIXM::Association::Array.

Find objects of the given class and optionally with the given attribute values previously written to AIXM.


87
88
89
90
91
# File 'lib/aipp/aip.rb', line 87

%i(find_by find).each do |method|
  define_method method do |*args|
    aixm.features.send(method, *args)
  end
end

#given(*objects) ⇒ Object #given(*objects) {|Array<Object>| ... } ⇒ Object

Overloads:

  • #given(*objects) ⇒ Object

    Return objects unless at least one of them equals nil

    Examples:

    # Instead of this:
    first, last = unless ((first = expensive_first).nil? || (last = expensive_last).nil?)
      [first, last]
    end
    
    # Use the following:
    first, last = given(expensive_first, expensive_last)

    Parameters:

    • *objects (Array<Object>)

      any objects really

    Returns:

    • (Object)

      nil if at least one of the objects is nil, given objects otherwise

  • #given(*objects) {|Array<Object>| ... } ⇒ Object

    Yield objects unless at least one of them equals nil

    Examples:

    # Instead of this:
    name = unless ((first = expensive_first.nil? || (last = expensive_last.nil?)
      "#{first} #{last}"
    end
    
    # Use any of the following:
    name = given(expensive_first, expensive_last) { |f, l| "#{f} #{l}" }
    name = given(expensive_first, expensive_last) { "#{_1} #{_2}" }

    Parameters:

    • *objects (Array<Object>)

      any objects really

    Yields:

    • (Array<Object>)

      objects passed as parameter

    Returns:

    • (Object)

      nil if at least one of the objects is nil, return of block otherwise


126
127
128
129
130
# File 'lib/aipp/aip.rb', line 126

def given(*objects)
  if objects.none?(&:nil?)
    block_given? ? yield(*objects) : objects
  end
end

#inspectString

Returns:


42
43
44
# File 'lib/aipp/aip.rb', line 42

def inspect
  "#<AIPP::AIP #{aip}>"
end

Build and optionally check a Markdown link

Examples:

options[:check_links] = false
link_to('foo', 'https://bar.com/exists')      # => "[foo](https://bar.com/exists)"
link_to('foo', 'https://bar.com/not-found')   # => "[foo](https://bar.com/not-found)"
options[:check_links] = true
link_to('foo', 'https://bar.com/exists')      # => "[foo](https://bar.com/exists)"
link_to('foo', 'https://bar.com/not-found')   # => nil

Returns:

  • (String, nil)

    Markdown link


145
146
147
# File 'lib/aipp/aip.rb', line 145

def link_to(body, url)
  "[#{body}](#{url})" if !options[:check_links] || url_exists?(url)
end

#optionsObject

See Also:


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

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

#read(aip_file = nil) ⇒ Nokogiri::XML::Document, ...

Read an AIP source file

Read the cached source file if it exists in the source archive. Otherwise, download it from URL and cache it.

An URL builder method url_for(aip_file) must be implemented by 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 with section stripped e.g. “AD-1.3-2” -> “AD-1.3”)

Returns:

  • (Nokogiri::XML::Document, Nokogiri::HTML5::Document, Roo::Spreadsheet, String)

    XML/HTML as Nokogiri document, XLSX/ODS/CSV as Roo document, PDF and TXT as String


59
60
61
62
63
# File 'lib/aipp/aip.rb', line 59

def read(aip_file=nil)
  @aip_file = aip_file || aip.remove(/(?<![A-Z])-\d+$/)
  url = url_for(@aip_file)   # may update aip_file string
  @downloader.read(document: @aip_file, url: url)
end