lib/aixm/feature/navigational_aid/designated_point.rb in aixm-0.2.3 vs lib/aixm/feature/navigational_aid/designated_point.rb in aixm-0.3.0

- old
+ new

@@ -1,82 +1,78 @@ +using AIXM::Refinements + module AIXM - module Feature - module NavigationalAid + class Feature + class NavigationalAid - ## - # Designated points are named map coordinates + # Named geographical location used in defining an ATS route, aircraft + # flight paths or for other navigation purposes. # - # Types: - # * +:icao+ (+:ICAO+) - ICAO 5 letter name code designator - # * +:adhp+ (+:ADHP+) - aerodrome/heliport related name code designator - # * +:coordinates+ (+:COORD+) - point with identifier derived from its - # geographical coordinates - class DesignatedPoint < Base - using AIXM::Refinements + # ===Cheat Sheet in Pseudo Code: + # designated_point = AIXM.designated_point( + # source: String or nil + # region: String or nil (falls back to AIXM.config.region) + # id: String + # name: String or nil + # xy: AIXM.xy + # type: TYPES + # ) + # designated_point.remarks = String or nil + # + # @see https://github.com/openflightmaps/ofmx/wiki/Navigational-aid#dpn-designated-point + class DesignatedPoint < NavigationalAid + public_class_method :new + private :organisation= + private :organisation TYPES = { - ICAO: :icao, - ADHP: :adhp, - COORD: :coordinates + ICAO: :icao, # five-letter ICAO name + ADHP: :adhp, # airport related name + COORD: :coordinates, # derived from geographical coordinates + OTHER: :other # specify in remarks }.freeze + # @return [Symbol] type of designated point attr_reader :type - public_class_method :new - - def initialize(id:, name: nil, xy:, z: nil, type:) - super(id: id, name: name, xy: xy, z: z) + def initialize(type:, **arguments) + super(organisation: false, z: nil, **arguments) self.type = type end def type=(value) - @type = TYPES.lookup(value&.to_sym, nil) || fail(ArgumentError, "invalid type") + @type = TYPES.lookup(value&.to_s&.to_sym, nil) || fail(ArgumentError, "invalid type") end - def type_key - TYPES.key(type) - end - - ## - # Digest to identify the payload - def to_digest - [super, type].to_digest - end - - ## - # Render UID markup - def to_uid(*extensions) + # @return [String] UID markup + def to_uid builder = Builder::XmlMarkup.new(indent: 2) - builder.DpnUid({ mid: to_digest, newEntity: (true if extensions >> :ofm) }.compact) do |dpnuid| - dpnuid.codeId(id) - dpnuid.geoLat(xy.lat(format_for(*extensions))) - dpnuid.geoLong(xy.long(format_for(*extensions))) + builder.DpnUid({ region: (region if AIXM.ofmx?) }.compact) do |dpn_uid| + dpn_uid.codeId(id) + dpn_uid.geoLat(xy.lat(AIXM.schema)) + dpn_uid.geoLong(xy.long(AIXM.schema)) end end - ## - # Render AIXM markup - def to_aixm(*extensions) - builder = to_builder(*extensions) - builder.Dpn do |dpn| - dpn << to_uid(*extensions).indent(2) - dpn.OrgUid - dpn.txtName(name) if name + # @return [String] AIXM or OFMX markup + def to_xml + builder = to_builder + builder.Dpn({ source: (source if AIXM.ofmx?) }.compact) do |dpn| + dpn << to_uid.indent(2) dpn.codeDatum('WGE') dpn.codeType(type_key.to_s) - if z - dpn.valElev(z.alt) - dpn.uomDistVer(z.unit.to_s) - end - if schedule - dpn.Dtt do |dtt| - dtt << schedule.to_aixm(*extensions).indent(4) - end - end + dpn.txtName(name) if name dpn.txtRmk(remarks) if remarks - dpn.target! # see https://github.com/jimweirich/builder/issues/42 + dpn.target! end end + + private + + def type_key + TYPES.key(type) + end + end end end end