Class: AIPP::Parser Abstract
- Inherits:
-
Object
- Object
- AIPP::Parser
- Defined in:
- lib/aipp/parser.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#aixm ⇒ AIXM::Document
readonly
AIXM document instance.
Class Method Summary collapse
-
.dependencies ⇒ Array<String>
Declared dependencies.
-
.depends_on(*dependencies) ⇒ Object
Declare a dependency.
Instance Method Summary collapse
-
#add(feature) ⇒ AIXM::Feature
Add feature to AIXM.
-
#find(object) ⇒ Object
Find equal objects previously written to AIXM.
-
#find_by(klass, attributes = {}) ⇒ Object
Find objects of the given class and optionally with the given attribute values previously written to AIXM.
- #given(*objects) ⇒ Object
-
#initialize(downloader:, aixm:) ⇒ Parser
constructor
A new instance of Parser.
- #inspect ⇒ String
-
#link_to(body, url) ⇒ String?
Build and optionally check a Markdown link.
- #origin_for ⇒ Object abstract
-
#read(document = section) ⇒ Nokogiri::XML::Document, ...
Read a source document.
- #section ⇒ String
Methods included from Patcher
#attach_patches, #detach_patches, included
Methods included from Debugger
#info, #original_warn, #verbose_info, #warn, #with_debugger
Constructor Details
#initialize(downloader:, aixm:) ⇒ Parser
Returns a new instance of Parser.
29 30 31 32 |
# File 'lib/aipp/parser.rb', line 29 def initialize(downloader:, aixm:) @downloader, @aixm = downloader, aixm setup if respond_to? :setup end |
Instance Attribute Details
#aixm ⇒ AIXM::Document (readonly)
Returns AIXM document instance.
9 10 11 |
# File 'lib/aipp/parser.rb', line 9 def aixm @aixm end |
Class Method Details
.dependencies ⇒ Array<String>
Declared dependencies
24 25 26 |
# File 'lib/aipp/parser.rb', line 24 def dependencies @dependencies || [] end |
.depends_on(*dependencies) ⇒ Object
Declare a dependency
16 17 18 |
# File 'lib/aipp/parser.rb', line 16 def depends_on(*dependencies) @dependencies = dependencies.map(&:to_s) end |
Instance Method Details
#add(feature) ⇒ AIXM::Feature
Add feature to AIXM
72 73 74 75 76 |
# File 'lib/aipp/parser.rb', line 72 def add(feature) verbose_info "adding #{feature.inspect}" aixm.add_feature feature feature end |
#find(object) ⇒ Object
This method is delegated to AIXM::Association::Array
.
Find equal objects previously written to AIXM.
90 91 92 93 94 |
# File 'lib/aipp/parser.rb', line 90 %i(find_by find).each do |method| define_method method do |*args| aixm.features.send(method, *args) end end |
#find_by(klass, attributes = {}) ⇒ Object
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.
90 91 92 93 94 |
# File 'lib/aipp/parser.rb', line 90 %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
129 130 131 132 133 |
# File 'lib/aipp/parser.rb', line 129 def given(*objects) if objects.none?(&:nil?) block_given? ? yield(*objects) : objects end end |
#inspect ⇒ String
35 36 37 |
# File 'lib/aipp/parser.rb', line 35 def inspect "#<AIPP::Parser #{section}>" end |
#link_to(body, url) ⇒ String?
Build and optionally check a Markdown link
148 149 150 |
# File 'lib/aipp/parser.rb', line 148 def link_to(body, url) "[#{body}](#{url})" if !AIPP..check_links || url_exists?(url) end |
#origin_for ⇒ Object
45 46 47 |
# File 'lib/aipp/parser.rb', line 45 def origin_for(*) fail "origin_for method must be implemented in parser" end |
#read(document = section) ⇒ Nokogiri::XML::Document, ...
Read a source document
Read the cached document if it exists in the source archive. Otherwise, download and cache it.
An origin builder method origin_for
must be implemented by the parser definition.
61 62 63 64 65 66 |
# File 'lib/aipp/parser.rb', line 61 def read(document=section) @downloader.read( document: document, origin: origin_for(document) ) end |
#section ⇒ String
40 41 42 |
# File 'lib/aipp/parser.rb', line 40 def section self.class.to_s.sectionize end |