Class: AIXM::Feature::Unit

Inherits:
AIXM::Feature show all
Defined in:
lib/aixm/feature/unit.rb

Overview

Units providing all kind of services such as air traffic management, search and rescue, meteorological services and so forth.

Cheat Sheet in Pseudo Code:

unit = AIXM.unit(
  source: String or nil
  organisation: AIXM.organisation
  name: String
  type: TYPES
  class: :icao or :other
)
unit.airport = AIXM.airport or nil
unit.remarks = String or nil
unit.add_service(AIXM.service)

Constant Summary collapse

TYPES =
{
  ACC: :area_control_centre,
  APP: :approach_control_office,
  ARO: :ats_reporting_office,
  ATSU: :air_traffic_services_unit,
  COM: :communications_office,
  FIC: :flight_information_centre,
  FSS: :flight_service_station,
  MET: :meteorological_office,
  NOF: :international_notam_office,
  RAD: :radar_office,
  TWR: :aerodrome_control_tower,
  OTHER: :other                       # specify in remarks
}.freeze
CLASSES =
{
  ICAO: :icao,
  OTHER: :other   # specify in remarks
}.freeze

Instance Attribute Summary collapse

Attributes inherited from AIXM::Feature

#source

Instance Method Summary collapse

Methods inherited from AIXM::Feature

#==

Constructor Details

#initialize(source: nil, organisation:, name:, type:, class:) ⇒ Unit


60
61
62
63
64
65
# File 'lib/aixm/feature/unit.rb', line 60

def initialize(source: nil, organisation:, name:, type:, class:)
  super(source: source)
  self.organisation, self.name, self.type = organisation, name, type
  self.class = binding.local_variable_get(:class)
  @services = []
end

Instance Attribute Details

#airportAIXM::Feature::Airport?


55
56
57
# File 'lib/aixm/feature/unit.rb', line 55

def airport
  @airport
end

#classSymbol


88
89
90
# File 'lib/aixm/feature/unit.rb', line 88

def class
  @klass
end

#nameString


49
50
51
# File 'lib/aixm/feature/unit.rb', line 49

def name
  @name
end

#organisationAIXM::Feature::Organisation


46
47
48
# File 'lib/aixm/feature/unit.rb', line 46

def organisation
  @organisation
end

#remarksString?


58
59
60
# File 'lib/aixm/feature/unit.rb', line 58

def remarks
  @remarks
end

#servicesArray<AIXM::Component::Service> (readonly)


118
119
120
# File 'lib/aixm/feature/unit.rb', line 118

def services
  @services.sort { |a, b| [a.type, a.name] <=> [b.type, b.name] }
end

#typeSymbol


52
53
54
# File 'lib/aixm/feature/unit.rb', line 52

def type
  @type
end

Instance Method Details

#add_service(service) ⇒ self

Add a service provided by this unit.


109
110
111
112
113
114
# File 'lib/aixm/feature/unit.rb', line 109

def add_service(service)
  fail(ArgumentError, "invalid service") unless service.is_a? AIXM::Component::Service
  service.send(:unit=, self)
  @services << service
  self
end

#inspectString


68
69
70
# File 'lib/aixm/feature/unit.rb', line 68

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

#to_uidString


123
124
125
126
127
128
# File 'lib/aixm/feature/unit.rb', line 123

def to_uid
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.UniUid do |uni_uid|
    uni_uid.txtName(name)
  end
end

#to_xmlString


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/aixm/feature/unit.rb', line 131

def to_xml
  builder = Builder::XmlMarkup.new(indent: 2)
  builder.comment! "Unit: #{name}"
  builder.Uni({ source: (source if AIXM.ofmx?) }.compact) do |uni|
    uni << to_uid.indent(2)
    uni << organisation.to_uid.indent(2)
    uni << airport.to_uid.indent(2) if airport
    uni.codeType(TYPES.key(type).to_s)
    uni.codeClass(CLASSES.key(self.class).to_s)
    uni.txtRmk(remarks) if remarks
  end
  services.each.with_object({}) do |service, sequences|
    sequences[service.type] = (sequences[service.type] || 0) + 1
    builder << service.to_xml(sequences[service.type])
  end
  builder.target!
end