Class: Stupidedi::Editor::TransmissionEd

Inherits:
AbstractEd
  • Object
show all
Defined in:
lib/stupidedi/editor/transmission_ed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractEd

#edit, edit, #rewrite, rewrite

Methods included from Inspect

#inspect

Constructor Details

#initialize(config, received) ⇒ TransmissionEd

Returns a new instance of TransmissionEd.



13
14
15
16
# File 'lib/stupidedi/editor/transmission_ed.rb', line 13

def initialize(config, received)
  @config, @received =
    config, received
end

Instance Attribute Details

#configConfig (readonly)

Returns:



8
9
10
# File 'lib/stupidedi/editor/transmission_ed.rb', line 8

def config
  @config
end

#receivedTime (readonly)

Returns:

  • (Time)


11
12
13
# File 'lib/stupidedi/editor/transmission_ed.rb', line 11

def received
  @received
end

Instance Method Details

#critique(machine) ⇒ ResultSet

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/stupidedi/editor/transmission_ed.rb', line 19

def critique(machine)
  ResultSet.new.tap do |acc|
    m, index = machine.first, Hash.new{|h,k| h[k] = [] }

    # Collect all the ISA13 elements within this transmission
    while m.defined?
      m = m.flatmap do |isa|
        critique_isa(isa, acc)

        # There isn't a well-defined constraint in the specs regarding
        # the uniqueness of control numbers, but one of the foundation
        # standards documents suggests the combination of ISA05, ISA06,
        # ISA07, ISA08, and ISA13 "shall be unique within a reasonably
        # extended time frame whose boundaries shall be defined by
        # trading partner agreement".
        isa.element(5).tap do |e5|
          isa.element(6).tap do |e6|
            isa.element(7).tap do |e7|
              isa.element(8).tap do |e8|
                isa.element(13).tap do |e13|
                  key  = []
                  key <<  e5.node.to_s
                  key <<  e6.node.to_s
                  key <<  e7.node.to_s
                  key <<  e8.node.to_s
                  key << e13.node.to_s

                  isa.segment.tap{|s| index[key] << s }
                end
              end
            end
          end
        end

        isa.find!(:ISA)
      end
    end

    edit(:ISA) do
      index.each do |key, dupes|
        dupes.tail.each do |s|
          acc.ta105(s, "R", "025",
            "control number must be unique per sender and receiver")
        end
      end
    end
  end
end