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,
  ADSU: :automatic_dependent_surveillance_unit,
  ADVC: :advisory_centre,
  ALPS: :alerting_post,
  AOF: :aeronautical_information_services_office,
  APP: :approach_control_office,
  'APP-ARR': :arrivals_approach_control_office,
  'APP-DEP': :depatures_approach_control_office,
  ARO: :air_traffic_service_reporting_office,
  ARTCC: :air_route_traffic_control_centre,
  ATCC: :air_traffic_control_centre,
  ATFMU: :air_traffic_flow_management_unit,
  ATMU: :air_traffic_management_unit,
  ATSU: :air_traffic_services_unit,
  BOF: :briefing_office,
  BS: :commercial_broadcasting_station,
  COM: :communications_office,
  FCST: :forecasting_office,
  FIC: :flight_information_centre,
  FSS: :flight_service_station,
  GCA: :ground_controlled_approach_systems_office,
  MET: :meteorological_office,
  MIL: :military_station,
  MILOPS: :military_flight_operations_briefing_office,
  MWO: :meteorological_watch_office,
  NOF: :international_notam_office,
  OAC: :oceanic_control_centre,
  PAR: :precision_approach_radar_centre,
  RAD: :radar_office,
  RAFC: :regional_area_forecast_centre,
  RCC: :rescue_coordination_centre,
  RSC: :rescue_sub_centre,
  SAR: :search_and_rescue_centre,
  SMC: :surface_movement_control_office,
  SMR: :surface_movement_radar_office,
  SRA: :surveillance_radar_approach_centre,
  SSR: :secondary_surveillance_radar_centre,
  TAR: :terminal_area_surveillance_radar_centre,
  TRACON: :terminal_radar_approach_control,
  TWR: :aerodrome_control_tower,
  UAC: :upper_area_control_centre,
  UDF: :uhf_direction_finding_station,
  UIC: :upper_information_centre,
  VDF: :vdf_direction_finding_station,
  WAFC: :world_area_forecast_centre,
  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

Returns a new instance of Unit


94
95
96
97
98
99
# File 'lib/aixm/feature/unit.rb', line 94

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?

Returns airport

Returns:


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

def airport
  @airport
end

#classSymbol

Note:

Use original_class to query the Ruby object class.

Returns class of unit (see CLASSES)

Returns:

  • (Symbol)

    class of unit (see CLASSES)


123
# File 'lib/aixm/feature/unit.rb', line 123

alias_method :original_class, :class

#nameString

Returns name of unit (e.g. “MARSEILLE ACS”)

Returns:

  • (String)

    name of unit (e.g. “MARSEILLE ACS”)


83
84
85
# File 'lib/aixm/feature/unit.rb', line 83

def name
  @name
end

#organisationAIXM::Feature::Organisation

Returns superior organisation

Returns:


80
81
82
# File 'lib/aixm/feature/unit.rb', line 80

def organisation
  @organisation
end

#remarksString?

Returns free text remarks

Returns:

  • (String, nil)

    free text remarks


92
93
94
# File 'lib/aixm/feature/unit.rb', line 92

def remarks
  @remarks
end

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

Returns services provided by this unit

Returns:


154
155
156
# File 'lib/aixm/feature/unit.rb', line 154

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

#typeSymbol

Returns type of unit (see TYPES)

Returns:

  • (Symbol)

    type of unit (see TYPES)


86
87
88
# File 'lib/aixm/feature/unit.rb', line 86

def type
  @type
end

Instance Method Details

#add_service(service) ⇒ self

Add a service provided by this unit.

Parameters:

Returns:

  • (self)

145
146
147
148
149
150
# File 'lib/aixm/feature/unit.rb', line 145

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

#inspectString

Returns:

  • (String)

102
103
104
# File 'lib/aixm/feature/unit.rb', line 102

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

#original_classSymbol

Note:

Use original_class to query the Ruby object class.

Returns class of unit (see CLASSES)

Returns:

  • (Symbol)

    class of unit (see CLASSES)


123
# File 'lib/aixm/feature/unit.rb', line 123

alias_method :original_class, :class

#to_uidString

Returns UID markup

Returns:

  • (String)

    UID markup


159
160
161
162
163
164
# File 'lib/aixm/feature/unit.rb', line 159

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

#to_xmlString

Returns AIXM or OFMX markup

Returns:

  • (String)

    AIXM or OFMX markup


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/aixm/feature/unit.rb', line 167

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(sequence: sequences[service.type])
  end
  builder.target!
end