Class: Stupidedi::Config::InterchangeConfig
- Inherits:
-
Object
- Object
- Stupidedi::Config::InterchangeConfig
- 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 Attribute Summary collapse
Instance Method Summary collapse
- #at(version) ⇒ InterchangeDef
- #customize(&block)
-
#initialize ⇒ InterchangeConfig
constructor
A new instance of InterchangeConfig.
- #pretty_print(q)
- #register(version, definition = nil, &constructor)
Methods included from Inspect
Constructor Details
#initialize ⇒ InterchangeConfig
Returns a new instance of InterchangeConfig.
37 38 39 |
# File 'lib/stupidedi/config/interchange_config.rb', line 37 def initialize @table = Hash.new end |
Instance Attribute Details
#table ⇒ Hash<String, InterchangeDef> (readonly)
33 34 35 |
# File 'lib/stupidedi/config/interchange_config.rb', line 33 def table @table end |
Instance Method Details
#at(version) ⇒ InterchangeDef
64 65 66 67 |
# File 'lib/stupidedi/config/interchange_config.rb', line 64 def at(version) x = @table[version] x.is_a?(Proc) ? x.call : x end |
#customize(&block)
41 42 43 |
# File 'lib/stupidedi/config/interchange_config.rb', line 41 def customize(&block) tap(&block) end |
#pretty_print(q)
This method returns an undefined value.
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/stupidedi/config/interchange_config.rb', line 70 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)
This method returns an undefined value.
55 56 57 58 59 60 61 |
# File 'lib/stupidedi/config/interchange_config.rb', line 55 def register(version, definition = nil, &constructor) if block_given? @table[version] = constructor else @table[version] = definition end end |