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.
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
17
18
19
|
# File 'lib/stupidedi/values/interchange_val.rb', line 17
def children
@children
end
|
#definition ⇒ InterchangeDef
14
15
16
|
# File 'lib/stupidedi/values/interchange_val.rb', line 14
def definition
@definition
end
|
Instance Method Details
#==(other) ⇒ 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
|
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
|
#inspect ⇒ 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
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
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?)
isa = definition.replace_separators(isa, whole)
copy \
:children => isa.snoc(head) + tail,
:separators => whole
end
|
#segment_dict ⇒ Module
41
42
43
|
# File 'lib/stupidedi/values/interchange_val.rb', line 41
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
51
52
53
|
# File 'lib/stupidedi/values/interchange_val.rb', line 51
def separators
@separators.merge(definition.separators(@children.find(&:segment?)))
end
|