class AIXM::Component::Service
Service
provided by a unit.
Cheat Sheet in Pseudo Code:¶ ↑
service = AIXM.service( type: TYPES ) service.timetable = AIXM.timetable or nil service.remarks = String or nil service.add_frequency(AIXM.frequency)
@see gitlab.com/openflightmaps/ofmx/wikis/Organisation#ser-service
Constants
- GUESSED_UNIT_TYPES_MAP
Map service types to guessed unit types
- TYPES
Attributes
remarks[R]
@return [String, nil] free text remarks
timetable[R]
@return [AIXM::Component::Timetable, nil] operating hours
type[R]
@return [Symbol] type of service (see {TYPES})
Public Class Methods
new(type:)
click to toggle source
# File lib/aixm/component/service.rb 153 def initialize(type:) 154 self.type = type 155 @sequence = 1 156 end
Public Instance Methods
guessed_unit_type()
click to toggle source
Guess the unit type for this service
@return [Symbol, nil] guessed unit type or nil
if unmappable
# File lib/aixm/component/service.rb 179 def guessed_unit_type 180 GUESSED_UNIT_TYPES_MAP[type] 181 end
inspect()
click to toggle source
@return [String]
# File lib/aixm/component/service.rb 159 def inspect 160 %Q(#<#{self.class} type=#{type.inspect}>) 161 end
remarks=(value)
click to toggle source
# File lib/aixm/component/service.rb 172 def remarks=(value) 173 @remarks = value&.to_s 174 end
timetable=(value)
click to toggle source
# File lib/aixm/component/service.rb 167 def timetable=(value) 168 fail(ArgumentError, "invalid timetable") unless value.nil? || value.is_a?(AIXM::Component::Timetable) 169 @timetable = value 170 end
to_uid()
click to toggle source
@return [String] UID markup
# File lib/aixm/component/service.rb 184 def to_uid 185 resequence! 186 builder = Builder::XmlMarkup.new(indent: 2) 187 builder.SerUid do |ser_uid| 188 ser_uid << unit.to_uid.indent(2) 189 ser_uid.codeType(TYPES.key(type).to_s) 190 ser_uid.noSeq(@sequence) 191 end 192 end
to_xml()
click to toggle source
@return [String] AIXM
or OFMX markup
# File lib/aixm/component/service.rb 196 def to_xml 197 builder = Builder::XmlMarkup.new(indent: 2) 198 builder.comment! ["Service: #{TYPES.key(type)}", unit&.send(:name_with_type)].compact.join(' by ') 199 builder.Ser do |ser| 200 ser << to_uid.indent(2) 201 ser << timetable.to_xml(as: :Stt).indent(2) if timetable 202 ser.txtRmk(remarks) if remarks 203 end 204 frequencies.each do |frequency| 205 builder << frequency.to_xml 206 end 207 builder.target! 208 end
type=(value)
click to toggle source
# File lib/aixm/component/service.rb 163 def type=(value) 164 @type = TYPES.lookup(value&.to_s&.to_sym, nil) || fail(ArgumentError, "invalid type") 165 end
Private Instance Methods
resequence!()
click to toggle source
# File lib/aixm/component/service.rb 212 def resequence! 213 unit.services.sort { |a, b| a.type <=> b.type }.each.with_object({}) do |service, sequences| 214 sequences[service.type] = (sequences[service.type] || 0) + 1 215 service.instance_variable_set(:@sequence, sequences[service.type]) 216 end 217 end