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