Class: Stupidedi::Config::InterchangeConfig

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Inspect
Defined in:
lib/stupidedi/config/interchange_config.rb

Overview

The interchange control segments (ISA/ISE) are versioned independently from the functional group segments (GS/GE). Because different interchange versions can have unique grammars, this table serves as an indirection.

Opinion: The interchange version is encoded within the ISA segment, whose definition is recursively dependent on the interchange version. Worse yet, the version is encoded as the fourteenth element (in versions 00501 and 00401), instead of say, the 1st element.

This seems to indicate the versioning was an afterthought. The same thought process was applied when versioning the functional group segments, which has the version encoded in GS08.

The best we can do to cope with this is to presume the ISA and GS segments have an underlying grammar that won’t change between versions. We do this by parsing 12 things following “ISA”, using the 12th thing as the version number, and then starting over at “ISA” and parsing with actual grammar. Then the grammar can specify which elements specify delimiters and all the other parts of the interchange header, like the TA1 segment.

Instance Method Summary collapse

Methods included from Inspect

#inspect

Constructor Details

#initializeInterchangeConfig

Returns a new instance of InterchangeConfig.



34
35
36
# File 'lib/stupidedi/config/interchange_config.rb', line 34

def initialize
  @table = Hash.new
end

Instance Method Details

#at(version) ⇒ InterchangeDef

Returns:

  • (InterchangeDef)


59
60
61
62
# File 'lib/stupidedi/config/interchange_config.rb', line 59

def at(version)
  x = @table[version]
  x.is_a?(Proc) ? x.call : x
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/stupidedi/config/interchange_config.rb', line 65

def pretty_print(q)
  q.text "InterchangeConfig"
  q.group(2, "(", ")") do
    q.breakable ""
    @table.keys.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
  end
end

#register(version, definition = nil, &constructor) ⇒ void

This method returns an undefined value.

Examples:

table = InterchangeConfig.new

table.register("00602") { SixOhTwo::InterchangeDef }
table.register("00501") { FiveOhOne::InterchangeDef }
table.register("00401") { FourOhOne::InterchangeDef }
table.register("00304") { ThreeOhFour::InterchangeDef }


50
51
52
53
54
55
56
# File 'lib/stupidedi/config/interchange_config.rb', line 50

def register(version, definition = nil, &constructor)
  if block_given?
    @table[version] = constructor
  else
    @table[version] = definition
  end
end