Sha256: 1f7e8d343f5e8323fe40bdf08deb2d38529e821e1092543ddfeadfeb3c0cb3fd

Contents?: true

Size: 1.76 KB

Versions: 5

Compression:

Stored size: 1.76 KB

Contents

using AIXM::Refinements

module AIXM
  class Component

    # Timetables define activity time windows.
    #
    # @note As of now, only predefined timetables (see {CODES}) are imlemented.
    #
    # ===Cheat Sheat in Pseudo Code:
    #   timetable = AIXM.timetable(
    #     code: String or Symbol
    #   )
    #   timetable.remarks = String or nil
    #
    # ===Shortcuts:
    # * +AIXM::H24+ - continuous, all day and all night
    # * +AIXM::H_RE+ - pattern matching working hour codes
    #
    # @see https://github.com/openflightmaps/ofmx/wiki/Timetable#predefined-timetable
    class Timetable
      CODES = {
        H24: :continuous,           # all day and all night
        HJ: :sunrise_to_sunset,     # all day
        HN: :sunset_to_sunrise,     # all night
        HX: :unspecified,
        HO: :operational_request,   # on request only
        NOTAM: :notam,              # see NOTAM
        OTHER: :other               # specify in remarks
      }.freeze

      # @return [Symbol] predefined timetable code (see {CODES})
      attr_reader :code

      # @return [String, nil] free text remarks
      attr_reader :remarks

      def initialize(code:)
        self.code = code
      end

      # @return [String]
      def inspect
        %Q(#<#{self.class} code=#{code.inspect}>)
      end

      def code=(value)
        @code = CODES.lookup(value&.to_s&.to_sym, nil) || fail(ArgumentError, "invalid code")
      end

      def remarks=(value)
        @remarks = value&.to_s
      end

      # @return [String] AIXM or OFMX markup
      def to_xml(as: :Timetable)
        builder = Builder::XmlMarkup.new(indent: 2)
        builder.tag!(as) do |tag|
          tag.codeWorkHr(CODES.key(code).to_s)
          tag.txtRmkWorkHr(remarks) if remarks
        end
      end
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aixm-0.3.8 lib/aixm/component/timetable.rb
aixm-0.3.7 lib/aixm/component/timetable.rb
aixm-0.3.6 lib/aixm/component/timetable.rb
aixm-0.3.5 lib/aixm/component/timetable.rb
aixm-0.3.4 lib/aixm/component/timetable.rb