Sha256: 601b5e8138fee10df3d6c931af5a900ae7823dede9462817503e2530789afbbc

Contents?: true

Size: 919 Bytes

Versions: 1

Compression:

Stored size: 919 Bytes

Contents

module Eancom
  module Edifact
    class DTM < Segment
      TAG = 'DTM'.freeze
      TYPE = :body.freeze

      attr_accessor :type, :date_time, :format

      def initialize(
          tag: nil,
          type:,
          date_time:,
          format:
        )
        @tag = tag
        @type = type
        @date_time = date_time
        @format = format

        super(tag: @tag || TAG)
      end

      def to_json_hash
        hash = { identifier => {} }
        hash[identifier].merge!({ date_time: @date_time }) if @date_time

        hash.merge!({ identifier: @identifier }) if @identifier
        hash = {} if hash[identifier].empty?
        hash
      end

      def group_name
        'date_time_messages'
      end

      def segment_type
        TYPE
      end

      private

      def identifier
        @identifier ||= structure.find(:type).dictionary[@type][:identifier]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eancom-2.0.0 lib/eancom/edifact/segments/dtm.rb