Class: Stupidedi::Values::CompositeElementVal
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
#element?, #size
Methods inherited from AbstractVal
#blank?, #characters, #component?, #definition, #element?, #empty?, #functional_group?, #interchange?, #invalid?, #loop?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?, #valid?
Methods included from Color
ansi, #ansi
Methods included from Inspect
#inspect
Constructor Details
Returns a new instance of CompositeElementVal.
26
27
28
29
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 26
def initialize(children, usage)
@children, @usage =
children, usage
end
|
Instance Attribute Details
#children ⇒ Array<SimpleElementVal>
Also known as:
component_vals
18
19
20
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 18
def children
@children
end
|
#usage ⇒ CompositeElementUse
22
23
24
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 22
def usage
@usage
end
|
Instance Method Details
#==(other) ⇒ Boolean
92
93
94
95
96
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 92
def ==(other)
eql?(other) or
(other.definition == definition and
other.children == @children)
end
|
#composite? ⇒ Boolean
45
46
47
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 45
def composite?
true
end
|
32
33
34
35
36
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 32
def copy(changes = {})
CompositeElementVal.new \
changes.fetch(:children, @children),
changes.fetch(:usage, @usage)
end
|
50
51
52
53
54
55
56
57
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 50
def element(n)
unless n > 0
raise ArgumentError,
"n must be positive"
end
@children.at(n - 1)
end
|
#leaf? ⇒ Boolean
39
40
41
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 39
def leaf?
false
end
|
#pretty_print(q) ⇒ void
This method returns an undefined value.
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/stupidedi/values/composite_element_val.rb', line 60
def pretty_print(q)
id = definition.bind do |d|
"[#{d.id}: #{d.name}]".bind do |s|
if usage.forbidden?
ansi.forbidden(s)
elsif usage.required?
ansi.required(s)
else
ansi.optional(s)
end
end
end
q.text(ansi.composite("CompositeElementVal#{id}"))
if empty?
q.text(ansi.composite(".empty"))
else
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
end
|