Class: Stupidedi::Values::InterchangeVal

Inherits:
AbstractVal show all
Includes:
SegmentValGroup
Defined in:
lib/stupidedi/values/interchange_val.rb

Overview

See Also:

  • 3.2.1 Basic Interchange Service Request
  • B.1.1.4.1 Interchange Control Structures

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SegmentValGroup

#leaf?

Methods inherited from AbstractVal

#blank?, #characters, #component?, #composite?, #element?, #empty?, #functional_group?, #invalid?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?, #valid?

Methods included from Color

ansi, #ansi

Constructor Details

#initialize(definition, children, separators) ⇒ InterchangeVal



23
24
25
26
# File 'lib/stupidedi/values/interchange_val.rb', line 23

def initialize(definition, children, separators)
  @definition, @children, @separators =
    definition, children, separators
end

Instance Attribute Details

#childrenArray<SegmentVal, FunctionalGroupVal> (readonly)



19
20
21
# File 'lib/stupidedi/values/interchange_val.rb', line 19

def children
  @children
end

#definitionInterchangeDef (readonly)



16
17
18
# File 'lib/stupidedi/values/interchange_val.rb', line 16

def definition
  @definition
end

Instance Method Details

#==(other) ⇒ Boolean



95
96
97
98
99
# File 'lib/stupidedi/values/interchange_val.rb', line 95

def ==(other)
  eql?(other) or
   (other.definition == @definition and
    other.children   == @children)
end

#copy(changes = {}) ⇒ InterchangeVal



29
30
31
32
33
34
# File 'lib/stupidedi/values/interchange_val.rb', line 29

def copy(changes = {})
  InterchangeVal.new \
    changes.fetch(:definition, @definition),
    changes.fetch(:children, @children),
    changes.fetch(:separators, @separators)
end

#inspectString



90
91
92
# File 'lib/stupidedi/values/interchange_val.rb', line 90

def inspect
  ansi.envelope("Interchange") << "(#{@children.map(&:inspect).join(', ')})"
end

#interchange?Boolean



38
39
40
# File 'lib/stupidedi/values/interchange_val.rb', line 38

def interchange?
  true
end

#pretty_print(q) ⇒ void



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/stupidedi/values/interchange_val.rb', line 71

def pretty_print(q)
  id = @definition.try do |d|
    ansi.bold("[#{d.id.to_s}]")
  end

  q.text(ansi.envelope("InterchangeVal#{id}"))
  q.group(2, "(", ")") do
    q.breakable ""
    @children.each do |e|
      unless q.current_group.first?
        q.text ", "
        q.breakable
      end
      q.pp e
    end
  end
end

#replace_separators(replacement) ⇒ InterchangeVal



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/stupidedi/values/interchange_val.rb', line 58

def replace_separators(replacement)
  whole              = separators.merge(replacement)
  head, (isa, *tail) = @children.split_when(&:segment?)

  # replace ISA11 and ISA16 with given separators
  isa = definition.replace_separators(isa, whole)

  copy \
    :children   => isa.snoc(head) + tail,
    :separators => whole
end

#segment_dictModule



43
44
45
# File 'lib/stupidedi/values/interchange_val.rb', line 43

def segment_dict
  @definition.segment_dict
end

#separatorsReader::Separators

Note these will not contain the element and segment terminator, because those are not values stored as part of the interchange. Those values are stored in the state machine and can be retrieved by calling #separators on StateMachine



53
54
55
# File 'lib/stupidedi/values/interchange_val.rb', line 53

def separators
  @separators.merge(definition.separators(@children.find(&:segment?)))
end