Class: AIXM::Document
- Includes:
- 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
)
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 ⇒ Time
Creation date and time (default: #effective_at or now).
-
#effective_at ⇒ Time
Effective after date and time (default: #created_at or now).
-
#namespace ⇒ String
UUID to namespace the data contained in this document.
Instance Method Summary collapse
- #add_feature(feature) ⇒ self
-
#errors ⇒ Array<String>
Validate the generated AIXM or OFMX atainst it's 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) ⇒ 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.
Methods included from Association
Constructor Details
#initialize(namespace: nil, created_at: nil, effective_at: nil) ⇒ Document
Returns a new instance of Document.
39 40 41 |
# File 'lib/aixm/document.rb', line 39 def initialize(namespace: nil, created_at: nil, effective_at: nil) self.namespace, self.created_at, self.effective_at = namespace, created_at, effective_at end |
Instance Attribute Details
#created_at ⇒ Time
Returns creation date and time (default: #effective_at or now).
34 35 36 |
# File 'lib/aixm/document.rb', line 34 def created_at @created_at end |
#effective_at ⇒ Time
Returns effective after date and time (default: #created_at or now).
37 38 39 |
# File 'lib/aixm/document.rb', line 37 def effective_at @effective_at end |
#namespace ⇒ String
Returns UUID to namespace the data contained in this document.
31 32 33 |
# File 'lib/aixm/document.rb', line 31 def namespace @namespace end |
Instance Method Details
#add_feature(feature) ⇒ self
28 |
# File 'lib/aixm/document.rb', line 28 has_many :features, accept: ['AIXM::Feature'] |
#errors ⇒ Array<String>
Validate the generated AIXM or OFMX atainst it's XSD and return the errors found.
95 96 97 98 99 100 |
# File 'lib/aixm/document.rb', line 95 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.
28 |
# File 'lib/aixm/document.rb', line 28 has_many :features, accept: ['AIXM::Feature'] |
#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.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/aixm/document.rb', line 67 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
44 45 46 |
# File 'lib/aixm/document.rb', line 44 def inspect %Q(#<#{self.class} created_at=#{created_at.inspect}>) end |
#to_xml ⇒ String
Returns AIXM or OFMX markup.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/aixm/document.rb', line 103 def to_xml = { 'xmlns:xsi': AIXM.schema(:namespace), version: AIXM.schema(:version), origin: "rubygem aixm-#{AIXM::VERSION}", 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| AIXM::Memoize.method :to_uid do root << features.map { _1.to_xml }.join.indent(2) end end if AIXM.ofmx? && AIXM.config.mid AIXM::PayloadHash::Mid.new(builder.target!).insert_mid.to_xml else builder.target! end end |
#valid? ⇒ Boolean
Validate the generated AIXM or OFMX atainst it's XSD.
87 88 89 |
# File 'lib/aixm/document.rb', line 87 def valid? errors.none? end |