Class: Stupidedi::Config::InterchangeConfig
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
- #at(version) ⇒ InterchangeDef
-
#initialize ⇒ InterchangeConfig
constructor
A new instance of InterchangeConfig.
- #pretty_print(q) ⇒ void
- #register(version, definition = nil, &constructor) ⇒ void
Methods included from Inspect
Constructor Details
#initialize ⇒ InterchangeConfig
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
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.
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 |