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: message) puts document.to_s end private def type type = config.type.to_sym if Eancom::FILE_TYPES.include?(type) type else raise Eancom::Error.new("EANCOM FILE TYPE NOT VALID!") end end def name config.name end def message config.message end end end