Class: AIXM::Document
- Includes:
- Concerns::Association
- 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
expiration_at: Time or Date or String or nil
)
document.add_feature(AIXM::Feature)
Constant Summary collapse
- 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 ⇒ Object
Creation date and UTC time.
-
#effective_at ⇒ Object
Effective after date and UTC time.
-
#expiration_at ⇒ Object
Expiration after date and UTC time.
-
#namespace ⇒ Object
UUID to namespace the data contained in this document.
Instance Method Summary collapse
- #add_feature(feature) ⇒ self
-
#document ⇒ Nokogiri::XML::Document
Nokogiri AIXM or OFMX document.
-
#errors ⇒ Array<String>
Validate the generated AIXM or OFMX against its XSD and return the errors found.
-
#features ⇒ Array<AIXM::Feature>
Features (e.g. airport or airspace) present in this document.
-
#group_obstacles!(max_distance: AIXM.d(1, :nm)) ⇒ Integer
Compare all ungrouped obstacles and create new obstacle groups whose members are located within
max_distance
pairwise. -
#initialize(namespace: nil, created_at: nil, effective_at: nil, expiration_at: nil) ⇒ Document
constructor
See the cheat sheet for examples on how to create instances of this class.
- #inspect ⇒ String
-
#regions ⇒ Array<String>
Regions used throughout this document.
-
#to_xml ⇒ String
AIXM or OFMX markup.
-
#valid? ⇒ Boolean
Validate the generated AIXM or OFMX against its XSD.
Methods included from Concerns::Association
Constructor Details
#initialize(namespace: nil, created_at: nil, effective_at: nil, expiration_at: nil) ⇒ Document
See the cheat sheet for examples on how to create instances of this class.
66 67 68 69 |
# File 'lib/aixm/document.rb', line 66 def initialize(namespace: nil, created_at: nil, effective_at: nil, expiration_at: nil) self.namespace = namespace self.created_at, self.effective_at, self.expiration_at = created_at, effective_at, expiration_at end |
Instance Attribute Details
#created_at ⇒ Time #created_at=(value) ⇒ Object
Creation date and UTC time
46 47 48 |
# File 'lib/aixm/document.rb', line 46 def created_at @created_at end |
#effective_at ⇒ Time #effective_at=(value) ⇒ Object
Effective after date and UTC time
54 55 56 |
# File 'lib/aixm/document.rb', line 54 def effective_at @effective_at end |
#expiration_at ⇒ Time? #expiration_at=(value) ⇒ Object
Expiration after date and UTC time
62 63 64 |
# File 'lib/aixm/document.rb', line 62 def expiration_at @expiration_at end |
#namespace ⇒ String #namespace=(value) ⇒ Object
UUID to namespace the data contained in this document
38 39 40 |
# File 'lib/aixm/document.rb', line 38 def namespace @namespace end |
Instance Method Details
#add_feature(feature) ⇒ self
30 |
# File 'lib/aixm/document.rb', line 30 has_many :features, accept: ['AIXM::Feature'] |
#document ⇒ Nokogiri::XML::Document
Returns Nokogiri AIXM or OFMX document.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/aixm/document.rb', line 160 def document = { 'xmlns:xsi': AIXM.schema(:namespace), version: AIXM.schema(:version), origin: "rubygem aixm-#{AIXM::VERSION}", namespace: (namespace if AIXM.ofmx?), regions: (regions.join(' '.freeze) if AIXM.ofmx?), created: @created_at.xmlschema, effective: @effective_at.xmlschema, expiration: (@expiration_at&.xmlschema if AIXM.ofmx?) }.compact Nokogiri::XML::Builder.new do |builder| builder.send(AIXM.schema(:root), ) do |root| AIXM::Concerns::Memoize.method :to_uid do features.each { _1.add_to(root) } end if AIXM.ofmx? && AIXM.config.mid AIXM::PayloadHash::Mid.new(builder.doc).insert_mid end end end.doc end |
#errors ⇒ Array<String>
Validate the generated AIXM or OFMX against its XSD and return the errors found.
152 153 154 155 156 157 |
# File 'lib/aixm/document.rb', line 152 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 |
#features ⇒ Array<AIXM::Feature>
Returns features (e.g. airport or airspace) present in this document.
30 |
# File 'lib/aixm/document.rb', line 30 has_many :features, accept: ['AIXM::Feature'] |
#group_obstacles!(max_distance: AIXM.d(1, :nm)) ⇒ Integer
OFMX requires every obstacle, even single ones, to be part of an obstacle group which has a region assigned. For this to work, you must assure every obstacle has a region assigned when using this method.
Compare all ungrouped obstacles and create new obstacle groups whose members are located within max_distance
pairwise.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/aixm/document.rb', line 124 def group_obstacles!(max_distance: AIXM.d(1, :nm)) obstacles, list = features.find_by(:obstacle), {} while subject = obstacles.send(:shift) obstacles.each do |obstacle| if subject.xy.distance(obstacle.xy) <= max_distance [subject, obstacle].each { list[_1] = list[subject] || SecureRandom.uuid } end end end list.group_by(&:last).each do |_, grouped_list| first_obstacle = grouped_list.first.first obstacle_group = AIXM.obstacle_group(source: first_obstacle.source, region: first_obstacle.region) grouped_list.each { |o, _| obstacle_group.add_obstacle features.send(:delete, o) } add_feature obstacle_group end.count end |
#inspect ⇒ String
72 73 74 |
# File 'lib/aixm/document.rb', line 72 def inspect %Q(#<#{self.class} created_at=#{created_at.inspect}>) end |
#regions ⇒ Array<String>
Regions used throughout this document.
110 111 112 |
# File 'lib/aixm/document.rb', line 110 def regions features.map(&:region).uniq.sort end |
#to_xml ⇒ String
Returns AIXM or OFMX markup.
184 185 186 |
# File 'lib/aixm/document.rb', line 184 def to_xml document.pretty.to_xml end |
#valid? ⇒ Boolean
Validate the generated AIXM or OFMX against its XSD.
144 145 146 |
# File 'lib/aixm/document.rb', line 144 def valid? errors.none? end |