Class: Stupidedi::Values::InterchangeVal
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
#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
15
16
17
|
# File 'lib/stupidedi/values/interchange_val.rb', line 15
def children
@children
end
|
#definition ⇒ InterchangeDef
12
13
14
|
# File 'lib/stupidedi/values/interchange_val.rb', line 12
def definition
@definition
end
|
Instance Method Details
#==(other) ⇒ 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
|
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
|
87
88
89
|
# File 'lib/stupidedi/values/interchange_val.rb', line 87
def inspect
ansi.envelope("Interchange") << "(#{@children.map(&:inspect).join(', ')})"
end
|
#interchange? ⇒ Boolean
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
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?)
isa = definition.replace_separators(isa, whole)
copy \
:children => isa.snoc(head) + tail,
:separators => whole
end
|
#segment_dict ⇒ Module
40
41
42
|
# File 'lib/stupidedi/values/interchange_val.rb', line 40
def segment_dict
@definition.segment_dict
end
|
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
50
51
52
|
# File 'lib/stupidedi/values/interchange_val.rb', line 50
def separators
@separators.merge(definition.separators(@children.find(&:segment?)))
end
|