Class: Stupidedi::Config::InterchangeConfig

Inherits:
Object
  • Object
show all
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

Methods included from Inspect

#inspect

Constructor Details

#initializeInterchangeConfig

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

#tableHash<String, InterchangeDef> (readonly)

Returns:

  • (Hash<String, InterchangeDef>)


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

def table
  @table
end

Instance Method Details

#at(version) ⇒ InterchangeDef

Returns:

  • (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.

Examples:

table = InterchangeConfig.new

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


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