lib/aixm/feature/obstacle_group.rb in aixm-1.2.1 vs lib/aixm/feature/obstacle_group.rb in aixm-1.3.0

- old
+ new

@@ -9,15 +9,15 @@ # ===Cheat Sheet in Pseudo Code: # obstacle_group = AIXM.obstacle_group( # source: String or nil # see remarks below # region: String or nil # name: String or nil - # ).tap do |obstacle_group| - # obstacle_group.xy_accuracy = AIXM.d or nil - # obstacle_group.z_accuracy = AIXM.d or nil - # obstacle_group.remarks = String or nil - # end + # ) + # obstacle_group.xy_accuracy = AIXM.d or nil + # obstacle_group.z_accuracy = AIXM.d or nil + # obstacle_group.remarks = String or nil + # obstacle_group.comment = Object or nil # obstacle_group.add_obstacle( # add an obstacle to the group # AIXM.obstacle # ) # obstacle_group.add_obstacle( # add an obstacle to the group and link # AIXM.obstacle, # it to the obstacle last added to the group @@ -36,12 +36,11 @@ # group has no +source+ set, it will inherit this value from the first # obstacle in the group. # # @see https://gitlab.com/openflightmaps/ofmx/wikis/Obstacle class ObstacleGroup < Feature - include AIXM::Association - include AIXM::Memoize + include AIXM::Concerns::Association include AIXM::Concerns::Remarks public_class_method :new # @!method obstacles @@ -86,11 +85,11 @@ self.name = name end # @return [String] def inspect - %Q(#<#{self.class} #{@obstacles.count} obstacle(s)>) + %Q(#<#{self.class} #{obstacles.count} obstacle(s)>) end def name=(value) fail(ArgumentError, "invalid name") unless value.nil? || value.is_a?(String) @name = value&.uptrans @@ -104,41 +103,41 @@ def z_accuracy=(value) fail(ArgumentError, "invalid z accuracy") unless value.nil? || value.is_a?(AIXM::D) @z_accuracy = value end - # @return [String] UID markup - def to_uid - builder = Builder::XmlMarkup.new(indent: 2) + # @!visibility private + def add_uid_to(builder) builder.OgrUid({ region: (region if AIXM.ofmx?) }.compact) do |ogr_uid| ogr_uid.txtName(name) ogr_uid.geoLat(obstacles.first.xy.lat(AIXM.schema)) ogr_uid.geoLong(obstacles.first.xy.long(AIXM.schema)) end end - memoize :to_uid - # @return [String] AIXM or OFMX markup - def to_xml - builder = Builder::XmlMarkup.new(indent: 2) + # @!visibility private + def add_to(builder) if AIXM.ofmx? - builder.comment! "Obstacle group: #{name}".strip + builder.comment "Obstacle group: #{name}".dress + builder.text "\n" builder.Ogr({ source: (source if AIXM.ofmx?) }.compact) do |ogr| - ogr << to_uid.indent(2) + ogr.comment(indented_comment) if comment + add_uid_to(ogr) ogr.codeDatum('WGE') if xy_accuracy ogr.valGeoAccuracy(xy_accuracy.dim.trim) - ogr.uomGeoAccuracy(xy_accuracy.unit.upcase.to_s) + ogr.uomGeoAccuracy(xy_accuracy.unit.upcase) end if z_accuracy ogr.valElevAccuracy(z_accuracy.to_ft.dim.round) ogr.uomElevAccuracy('FT') end ogr.txtRmk(remarks) if remarks end end - obstacles.each { builder << _1.to_xml(delegate: false) } - builder.target! + obstacles.each do |obstacle| + obstacle.add_to(builder, delegate: false) + end end end end end