Class: Stupidedi::Values::InterchangeVal

Inherits:
AbstractVal show all
Extended by:
Forwardable
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.



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

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

Instance Attribute Details

#childrenArray<SegmentVal, FunctionalGroupVal> (readonly)



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

def children
  @children
end

#definitionInterchangeDef (readonly)

Returns:

  • (InterchangeDef)


12
13
14
# File 'lib/stupidedi/values/interchange_val.rb', line 12

def definition
  @definition
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#copy(changes = {}) ⇒ InterchangeVal

Returns:



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

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

#inspectString

Returns:



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

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

#interchange?Boolean

Returns:

  • (Boolean)

    true



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

def interchange?
  true
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



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

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:



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

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:



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

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:



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

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