-
Notifications
You must be signed in to change notification settings - Fork 137
/
abstract_val.rb
132 lines (106 loc) · 2.63 KB
/
abstract_val.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
module Stupidedi
using Refinements
module Values
class AbstractVal
include Inspect
include Color
# @return [SimpleElementDef, CompositeElementDef, LoopDef, SegmentDef, TableDef]
abstract :definition
# @see X222.pdf B.1.3.10 Absence of Data
def empty?
@children.all?(&:empty?)
end
abstract :leaf?
# Number of segments in this subtree
#
# @return [Integer]
def size
@children.sum(&:size)
end
# True except for {InvalidSegmentVal} and {AbstractElementVal} values
# that could not be parsed -- "abc" in a numeric field, for example.
def valid?
true
end
def invalid?
not valid?
end
# Is the element not blank?
def present?
not empty?
end
# Is the element not present?
def blank?
empty?
end
# Is this a {TransmissionVal}?
def transmission?
false
end
# Is this an {InterchangeVal}?
def interchange?
false
end
# Is this an {FunctionalGroupVal}?
def functional_group?
false
end
# Is this an {TransactionSetVal}?
def transaction_set?
false
end
# Is this a {TableVal}?
def table?
false
end
# Is this a {LoopVal}?
def loop?
false
end
# Is this a {SegmentVal} or {InvalidSegmentVal}?
def segment?
false
end
# Is this a {AbstractElementVal}?
def element?
false
end
# Is this a {CompositeElementVal}?
def composite?
false
end
# Is this a component {SimpleElementVal}?
def component?
false
end
# Is this a repeated {AbstractElementVal}?
def repeated?
false
end
# Is this a non-component {SimpleElementVal}?
def simple?
false
end
# Is this a simple element that represents a separator (delimiter)? For
# instance, ISA16 represents the repetition separator in version 00501.
def separator?
false
end
# Returns the set of characters that are used as data in this subtree, not
# including the separator (delimiter) elements found in the ISA segment.
#
# @return [AbstractSet<String>]
def characters(result = Sets.absolute([], Reader::C_BYTES.split(//)))
if leaf?
if present? and not separator?
result | to_x12.split(//)
else
result
end
else
children.inject(result){|r,c| c.characters(r) }
end
end
end
end
end