Class: AIXM::Document

Inherits:
Object
  • Object
show all
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

NAMESPACE_PATTERN =
/\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

Instance Method Summary collapse

Constructor Details

#initialize(region: nil, namespace: nil, created_at: nil, effective_at: nil) ⇒ Document

Returns a new instance of Document


35
36
37
38
# File 'lib/aixm/document.rb', line 35

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_atTime

Returns creation date and time (default: #effective_at or now)

Returns:

  • (Time)

    creation date and time (default: #effective_at or now)


27
28
29
# File 'lib/aixm/document.rb', line 27

def created_at
  @created_at
end

#effective_atTime

Returns effective after date and time (default: #created_at or now)

Returns:

  • (Time)

    effective after date and time (default: #created_at or now)


30
31
32
# File 'lib/aixm/document.rb', line 30

def effective_at
  @effective_at
end

#featuresArray<AIXM::Feature>

Returns airspaces, airports and other features

Returns:

  • (Array<AIXM::Feature>)

    airspaces, airports and other features


33
34
35
# File 'lib/aixm/document.rb', line 33

def features
  @features
end

#namespaceString

Returns UUID to namespace the data contained in this document

Returns:

  • (String)

    UUID to namespace the data contained in this document


24
25
26
# File 'lib/aixm/document.rb', line 24

def namespace
  @namespace
end

#regionString

Returns OFMX region all features in this document belong to

Returns:

  • (String)

    OFMX region all features in this document belong to


21
22
23
# File 'lib/aixm/document.rb', line 21

def region
  @region
end

Instance Method Details

#errorsArray<String>

Validate the generated AIXM or OFMX atainst it's XSD and return the errors found.

Returns:

  • (Array<String>)

    validation errors


74
75
76
77
78
79
# File 'lib/aixm/document.rb', line 74

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.message.match?(AIXM.config.ignored_errors)
  end
end

#inspectString

Returns:

  • (String)

41
42
43
# File 'lib/aixm/document.rb', line 41

def inspect
  %Q(#<#{self.class} created_at=#{created_at.inspect}>)
end

#to_xmlString

Returns AIXM or OFMX markup

Returns:

  • (String)

    AIXM or OFMX markup


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/aixm/document.rb', line 82

def to_xml
  meta = {
    '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), meta) 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.

Returns:

  • (Boolean)

    whether valid or not


66
67
68
# File 'lib/aixm/document.rb', line 66

def valid?
  errors.none?
end