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

Returns a new instance of InterchangeVal.



21
22
23
24
# File 'lib/stupidedi/values/interchange_val.rb', line 21

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

Instance Attribute Details

#childrenArray<SegmentVal, FunctionalGroupVal> (readonly)

Returns:



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

def children
  @children
end

#definitionInterchangeDef (readonly)

Returns:

  • (InterchangeDef)


14
15
16
# File 'lib/stupidedi/values/interchange_val.rb', line 14

def definition
  @definition
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
96
97
# File 'lib/stupidedi/values/interchange_val.rb', line 93

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

#copy(changes = {}) ⇒ InterchangeVal

Returns:



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

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

#inspectString

Returns:

  • (String)


88
89
90
# File 'lib/stupidedi/values/interchange_val.rb', line 88

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

#interchange?Boolean

Returns:

  • (Boolean)

    true



36
37
38
# File 'lib/stupidedi/values/interchange_val.rb', line 36

def interchange?
  true
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



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

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

Returns:



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

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

Returns:

  • (Module)


41
42
43
# File 'lib/stupidedi/values/interchange_val.rb', line 41

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

Returns:



51
52
53
# File 'lib/stupidedi/values/interchange_val.rb', line 51

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