Class: AIXM::Document
- Inherits:
-
Object
- Object
- AIXM::Document
- Defined in:
- lib/aixm/document.rb
Overview
The AIXM-Snapshot or OFMX-Snapshot document is the root container for aeronautical information such as airports or airspaces.
Cheat Sheet in Pseudo Code:
document = AIXM.document(
namespace: String (UUID)
created_at: Time or Date or String
effective_at: Time or Date or String
)
document.features << AIXM::Feature
Constant Summary collapse
- REGION_RE =
/\A[A-Z]{2}\z/.freeze
- NAMESPACE_RE =
/\A[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}\z/.freeze
Instance Attribute Summary collapse
-
#created_at ⇒ Time
Creation date and time (default: #effective_at or now).
-
#effective_at ⇒ Time
Effective after date and time (default: #created_at or now).
-
#features ⇒ Array<AIXM::Feature>
Airspaces, airports and other features.
-
#namespace ⇒ String
UUID to namespace the data contained in this document.
-
#region ⇒ String
OFMX region all features in this document belong to.
Instance Method Summary collapse
-
#errors ⇒ Array<String>
Validate the generated AIXM or OFMX atainst it’s XSD and return the errors found.
-
#initialize(region: nil, namespace: nil, created_at: nil, effective_at: nil) ⇒ Document
constructor
A new instance of Document.
- #inspect ⇒ String
-
#to_xml ⇒ String
AIXM or OFMX markup.
-
#valid? ⇒ Boolean
Validate the generated AIXM or OFMX atainst it’s XSD.
Constructor Details
#initialize(region: nil, namespace: nil, created_at: nil, effective_at: nil) ⇒ Document
Returns a new instance of Document.
37 38 39 40 |
# File 'lib/aixm/document.rb', line 37 def initialize(region: nil, namespace: nil, created_at: nil, effective_at: nil) self.region, self.namespace, self.created_at, self.effective_at = region, namespace, created_at, effective_at @features = [] end |
Instance Attribute Details
#created_at ⇒ Time
Returns creation date and time (default: #effective_at or now).
29 30 31 |
# File 'lib/aixm/document.rb', line 29 def created_at @created_at end |
#effective_at ⇒ Time
Returns effective after date and time (default: #created_at or now).
32 33 34 |
# File 'lib/aixm/document.rb', line 32 def effective_at @effective_at end |
#features ⇒ Array<AIXM::Feature>
Returns airspaces, airports and other features.
35 36 37 |
# File 'lib/aixm/document.rb', line 35 def features @features end |
#namespace ⇒ String
Returns UUID to namespace the data contained in this document.
26 27 28 |
# File 'lib/aixm/document.rb', line 26 def namespace @namespace end |
#region ⇒ String
Returns OFMX region all features in this document belong to.
23 24 25 |
# File 'lib/aixm/document.rb', line 23 def region @region end |
Instance Method Details
#errors ⇒ Array<String>
Validate the generated AIXM or OFMX atainst it’s XSD and return the errors found.
76 77 78 79 80 81 |
# File 'lib/aixm/document.rb', line 76 def errors xsd = Nokogiri::XML::Schema(File.open(AIXM.schema(:xsd))) xsd.validate(Nokogiri::XML(to_xml)).reject do |error| AIXM.config.ignored_errors && error..match?(AIXM.config.ignored_errors) end end |
#inspect ⇒ String
43 44 45 |
# File 'lib/aixm/document.rb', line 43 def inspect %Q(#<#{self.class} created_at=#{created_at.inspect}>) end |
#to_xml ⇒ String
Returns AIXM or OFMX markup.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/aixm/document.rb', line 84 def to_xml = { 'xmlns:xsi': AIXM.schema(:namespace), version: AIXM.schema(:version), origin: "rubygem aixm-#{AIXM::VERSION}", region: (region if AIXM.ofmx?), namespace: (namespace if AIXM.ofmx?), created: @created_at.xmlschema, effective: @effective_at.xmlschema }.compact builder = Builder::XmlMarkup.new(indent: 2) builder.instruct! builder.tag!(AIXM.schema(:root), ) do |root| root << features.map { |f| f.to_xml }.join.indent(2) end end |
#valid? ⇒ Boolean
Validate the generated AIXM or OFMX atainst it’s XSD.
68 69 70 |
# File 'lib/aixm/document.rb', line 68 def valid? errors.none? end |