Sha256: 137295114e9bce9aecd6de4b26164008c045ba05d1dc7d153415b128f412baf9

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module Eddy
  # Base class for EDI Segments.
  class Segment

    # An alphanumeric code unique to each Segment type.
    # @return [String]
    attr_reader :id
    # Short name of the Segment.
    # @return [String]
    attr_reader :name
    # @return [Array<Element>]
    attr_accessor :elements
    # @return [Eddy::Data::Store] Data passed down from a Transaction Set.
    attr_accessor :store

    # All of a Segment's elements need to be declared in its constructor.
    #
    # @param store [Eddy::Data::Store]
    # @param elements [Eddy::Element::Base]
    # @return [void]
    def initialize(store, *elements)
      self.store = store
      elements.flatten!
      self.elements = elements || []
    end

    # @param separator [String] (self.store.element_separator) String used to delimit elements within a segment.
    # @return [String]
    def render(separator = self.store.element_separator)
      segment = [self.id, self.elements.map(&:value)].join(separator)
      return Eddy::Util.trim_delims_from_segment(segment, separator: separator)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
eddy-0.5.1 lib/eddy/models/segment.rb
eddy-0.5.0 lib/eddy/models/segment.rb
eddy-0.4.0 lib/eddy/models/segment.rb
eddy-0.3.0 lib/eddy/models/segment.rb