lib/eancom.rb in eancom-0.1.0 vs lib/eancom.rb in eancom-1.1.0
- old
+ new
@@ -1,43 +1,86 @@
require 'eancom/version'
-require 'eancom/edifact'
module Eancom
class Error < StandardError; end
+ class StructureNotFoundError < StandardError; end
- FILE_TYPES = [
- :desadv,
- :pricat,
- :ordrsp,
- :salsrp,
- :invrp,
- :orders
- ]
+ FILE_TYPES = %I[
+ desadv
+ pricat
+ ordrsp
+ slsrpt
+ invrp
+ orders
+ ].freeze
- attr_accessor :definitions
+ DELIMITERS = {
+ component: ':',
+ data: '+',
+ release: '?',
+ decimal: '.',
+ reserve: ' ',
+ segment: '\''
+ }.freeze
+ attr_accessor :definitions, :segments
+
def self.definitions
- @@configs ||= Hash.new
+ @configs ||= {}
end
+ def self.segments
+ @segments ||= {}
+ end
+
+ def self.structures
+ @structures ||= {}
+ end
+
def self.register_definition(definition)
type = definition.type
name = definition.name
- definitions[type] ||= Hash.new
+ definitions[type] ||= {}
definitions[type][name] = definition
end
def self.find_definition(name:, type:)
definitions[type][name]
end
+
+ def self.register_segment(tag:, klass:)
+ segments[tag] ||= klass
+ end
+
+ def self.find_segment(tag:)
+ segments[tag]
+ end
+
+ def self.register_structure(tag:, structure:)
+ structures[tag] ||= structure
+ end
+
+ def self.find_structure(tag:)
+ structure = structures[tag]
+ if structure.nil?
+ raise StructureNotFoundError.new(
+ "Structure for tag: #{tag} not found."
+ )
+ end
+ structure
+ end
end
-require "eancom/factory"
-require "eancom/definition"
+# TODO: Describe why loaded here...
-spec = Gem::Specification.find_by_name("eancom")
+require 'eancom/edifact'
+require 'eancom/factory'
+require 'eancom/parser'
+require 'eancom/definition'
+
+spec = Gem::Specification.find_by_name('eancom')
gem_root = spec.gem_dir
-Dir[File.join(gem_root, "definitions", "**/*.rb")].sort.each do |file|
+Dir[File.join(gem_root, 'definitions', '**/*.rb')].sort.each do |file|
require file
end