Sha256: 09c9ab9ccf8c63d2272ab73530b65e28821b597bf539e3504f99af698850f307

Contents?: true

Size: 770 Bytes

Versions: 15

Compression:

Stored size: 770 Bytes

Contents

require 'json'

module Eancom
  class Factory

    attr_reader :config, :definition, :document

    def initialize(json:)
      @config = JSON.parse(json, object_class: OpenStruct)
      @document = Eancom::Edifact::Document.new
    end

    def build
      @definition = Eancom.find_definition(name: name, type: type)
      @definition.run(document: document, config: config)
      @document
    end

    private

    def type
      type = header.message_type.downcase.to_sym
      if Eancom::FILE_TYPES.include?(type)
        type
      else
        raise Eancom::Error.new("EANCOM FILE TYPE NOT VALID!")
      end
    end

    def header
      config.header
    end

    def name
      header.message_version_number + header.message_release_number
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
eancom-1.6.3 lib/eancom/factory.rb
eancom-1.6.2 lib/eancom/factory.rb
eancom-1.6.0 lib/eancom/factory.rb
eancom-1.5.7 lib/eancom/factory.rb
eancom-1.5.6 lib/eancom/factory.rb
eancom-1.5.5 lib/eancom/factory.rb
eancom-1.5.4 lib/eancom/factory.rb
eancom-1.5.2 lib/eancom/factory.rb
eancom-1.5.1 lib/eancom/factory.rb
eancom-1.5.0 lib/eancom/factory.rb
eancom-1.4.0 lib/eancom/factory.rb
eancom-1.3.0 lib/eancom/factory.rb
eancom-1.2.0 lib/eancom/factory.rb
eancom-1.1.1 lib/eancom/factory.rb
eancom-1.1.0 lib/eancom/factory.rb