rbedi 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/edi +897 -0
- data/lib/rbedi/codes/aaa.rb +437 -0
- data/lib/rbedi/codes/ak1.rb +278 -0
- data/lib/rbedi/codes/ak2.rb +336 -0
- data/lib/rbedi/codes/ak9.rb +55 -0
- data/lib/rbedi/codes/bht.rb +706 -0
- data/lib/rbedi/codes/codeset.rb +27 -0
- data/lib/rbedi/codes/dmg.rb +1583 -0
- data/lib/rbedi/codes/dtp.rb +1342 -0
- data/lib/rbedi/codes/eb.rb +1511 -0
- data/lib/rbedi/codes/eq.rb +286 -0
- data/lib/rbedi/codes/ge.rb +14 -0
- data/lib/rbedi/codes/gs.rb +287 -0
- data/lib/rbedi/codes/hl.rb +273 -0
- data/lib/rbedi/codes/iea.rb +14 -0
- data/lib/rbedi/codes/ik3.rb +32 -0
- data/lib/rbedi/codes/ik4.rb +37 -0
- data/lib/rbedi/codes/ik5.rb +56 -0
- data/lib/rbedi/codes/isa.rb +137 -0
- data/lib/rbedi/codes/le.rb +13 -0
- data/lib/rbedi/codes/ls.rb +13 -0
- data/lib/rbedi/codes/msg.rb +25 -0
- data/lib/rbedi/codes/n3.rb +14 -0
- data/lib/rbedi/codes/n4.rb +706 -0
- data/lib/rbedi/codes/nm1.rb +1916 -0
- data/lib/rbedi/codes/per.rb +308 -0
- data/lib/rbedi/codes/ref.rb +1749 -0
- data/lib/rbedi/codes/se.rb +14 -0
- data/lib/rbedi/codes/segment_names.rb +44 -0
- data/lib/rbedi/codes/st.rb +336 -0
- data/lib/rbedi/codes/trn.rb +22 -0
- data/lib/rbedi/codes.rb +8 -0
- data/lib/rbedi/edi_date_time.rb +69 -0
- data/lib/rbedi/functional_group.rb +52 -0
- data/lib/rbedi/non_existent_element_error.rb +4 -0
- data/lib/rbedi/parser.rb +102 -0
- data/lib/rbedi/segment.rb +114 -0
- data/lib/rbedi/transaction_envelope.rb +77 -0
- data/lib/rbedi/transaction_set.rb +40 -0
- data/lib/rbedi.rb +20 -4
- metadata +79 -10
data/bin/edi
ADDED
@@ -0,0 +1,897 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative "../lib/rbedi.rb"
|
3
|
+
require "argparse"
|
4
|
+
require "rbtext"
|
5
|
+
|
6
|
+
o = { :"raise-errors" => {}, :help => {} }
|
7
|
+
s = { c: { has_argument: true } }
|
8
|
+
|
9
|
+
args = ArgsParser::Args.new(options: o, switches: s)
|
10
|
+
|
11
|
+
transactions = {}
|
12
|
+
selected_transaction = nil
|
13
|
+
selected_functional_group = nil
|
14
|
+
selected_transaction_set = nil
|
15
|
+
selected_segment = nil
|
16
|
+
|
17
|
+
def list_transactions(transactions, selected=nil)
|
18
|
+
STDOUT.puts "Transactions (#{transactions.length}): "
|
19
|
+
transactions.each_with_index do |tx, i|
|
20
|
+
STDOUT.puts "#{selected == i ? ?* : " "}#{i.to_s.ljust(4)} | #{tx[1].interchange_control_number}, #{tx[1].functional_groups.length} functional group(s), #{tx[0]}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def list_functional_groups(transaction, selected=nil)
|
25
|
+
groups = transaction.functional_groups
|
26
|
+
STDOUT.puts "Functional groups (#{groups.length}): "
|
27
|
+
groups.each_with_index do |g, i|
|
28
|
+
STDOUT.puts "#{selected == i ? ?* : " "}#{i.to_s.ljust(4)} | #{g.group_control_number}, #{g.functional_identifier_code}, #{g.transaction_sets.length} tx set(s)"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_transaction_sets(functional_group, selected=nil)
|
33
|
+
sets = functional_group.transaction_sets
|
34
|
+
STDOUT.puts "Transaction sets (#{sets.length}): "
|
35
|
+
sets.each_with_index do |s, i|
|
36
|
+
STDOUT.puts "#{selected == i ? ?* : " "}#{i.to_s.ljust(4)} | #{s.transaction_set_control_number}, #{s.transaction_set_identifier_code}, #{s.segments.length} segment(s)"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def list_segments(transaction_set, selected=nil, filter: nil, search: nil, range: nil)
|
41
|
+
segs = transaction_set.segments
|
42
|
+
segsfil = segs.dup
|
43
|
+
if filter
|
44
|
+
segsfil = segs.filter do |s|
|
45
|
+
s.raw_segment_name == filter
|
46
|
+
end
|
47
|
+
elsif search
|
48
|
+
segsfil = segs.filter do |s|
|
49
|
+
s.to_s.match?(search)
|
50
|
+
end
|
51
|
+
elsif range
|
52
|
+
segsfil = segs[range]
|
53
|
+
end
|
54
|
+
STDOUT.puts "Segments (#{segsfil.length}): "
|
55
|
+
segs.each_with_index do |s, i|
|
56
|
+
unless segsfil.include?(s)
|
57
|
+
next
|
58
|
+
end
|
59
|
+
STDOUT.puts "#{selected == i ? ?* : " "}#{i.to_s.ljust(4)} | #{s.segment_type}, #{s.segment_elements.join(RBEDI::Codes::ELEMENT_SEPARATOR)}#{RBEDI::Codes::SEGMENT_TERMINATOR}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def help
|
64
|
+
STDOUT.puts "See https://matthiasclee.github.io/rbedi/cli.html"
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_transaction(transactions, id)
|
68
|
+
transactions.to_a[id][1]
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_functional_group(transactions, txid, fgid)
|
72
|
+
get_transaction(transactions, txid).functional_groups[fgid]
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_transaction_set(transactions, txid, fgid, tsid)
|
76
|
+
get_functional_group(transactions, txid, fgid).transaction_sets[tsid]
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_segment(transactions, txid, fgid, tsid, sgid)
|
80
|
+
get_transaction_set(transactions, txid, fgid, tsid).segments[sgid]
|
81
|
+
end
|
82
|
+
|
83
|
+
def repetition_separator(transactions, transaction)
|
84
|
+
get_transaction(transactions, transaction).repetition_separator
|
85
|
+
end
|
86
|
+
|
87
|
+
def dup_instance_variables(obj)
|
88
|
+
vars = obj.instance_variables
|
89
|
+
vars.each do |v|
|
90
|
+
obj.instance_variable_set(v, obj.instance_variable_get(v).dup)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def dup_strings(segment)
|
95
|
+
dup_instance_variables(segment)
|
96
|
+
segment.segment_elements.map!{|s|s.dup}
|
97
|
+
end
|
98
|
+
|
99
|
+
def dup_segments(ts)
|
100
|
+
dup_instance_variables(ts)
|
101
|
+
ts.segments.map!{|s|s.dup}
|
102
|
+
ts.segments.each {|s| dup_strings(s)}
|
103
|
+
end
|
104
|
+
|
105
|
+
def dup_transaction_sets(fg)
|
106
|
+
dup_instance_variables(fg)
|
107
|
+
fg.transaction_sets.map!{|s|s.dup}
|
108
|
+
fg.transaction_sets.each {|ts| dup_segments(ts)}
|
109
|
+
end
|
110
|
+
|
111
|
+
def dup_functional_groups(tx)
|
112
|
+
dup_instance_variables(tx)
|
113
|
+
tx.functional_groups.map!{|fg|fg.dup}
|
114
|
+
tx.functional_groups.each{|fg| dup_transaction_sets(fg)}
|
115
|
+
end
|
116
|
+
|
117
|
+
if args.options[:help]
|
118
|
+
help
|
119
|
+
exit
|
120
|
+
end
|
121
|
+
|
122
|
+
args.data.each do |filename|
|
123
|
+
if File.exist?(filename)
|
124
|
+
transactions[filename] = RBEDI::Parser.new(File.read(filename)).parse
|
125
|
+
else
|
126
|
+
STDERR.puts "#{filename} does not exist"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
STDOUT.puts "#{transactions.length} transaction#{?s unless transactions.length == 1} loaded"
|
131
|
+
if transactions.length == 1
|
132
|
+
selected_transaction = 0
|
133
|
+
if transactions.first[1].functional_groups.length == 1
|
134
|
+
selected_functional_group = 0
|
135
|
+
if transactions.first[1].functional_groups[0].transaction_sets.length == 1
|
136
|
+
selected_transaction_set = 0
|
137
|
+
if transactions.first[1].functional_groups[0].transaction_sets[0].segments.length == 1
|
138
|
+
selected_segment = 0
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
commands = []
|
145
|
+
presetcommands = false
|
146
|
+
if args.switches[:c]
|
147
|
+
commands = args.switches[:c].split(/\;[\s]*/)
|
148
|
+
presetcommands = true
|
149
|
+
end
|
150
|
+
|
151
|
+
loop do
|
152
|
+
begin
|
153
|
+
print "EDI> "
|
154
|
+
|
155
|
+
if !presetcommands
|
156
|
+
begin
|
157
|
+
command = STDIN.gets.chomp
|
158
|
+
rescue Interrupt
|
159
|
+
puts "Type 'exit' to quit"
|
160
|
+
next
|
161
|
+
end
|
162
|
+
else
|
163
|
+
(puts "exit"; exit) if commands.empty?
|
164
|
+
command = commands.delete_at(0)
|
165
|
+
puts command
|
166
|
+
if command == "switch"
|
167
|
+
presetcommands = false
|
168
|
+
next
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
command = command.scan(/"[^"]*"|\S+/).map { |s| s.gsub(/^"|"$/, '') }
|
173
|
+
|
174
|
+
case command[0]
|
175
|
+
when nil
|
176
|
+
next
|
177
|
+
when "switch"
|
178
|
+
presetcommands = true
|
179
|
+
next
|
180
|
+
when "clear"
|
181
|
+
R::S.clear
|
182
|
+
R::Cr.go_to_pos(0,0)
|
183
|
+
next
|
184
|
+
when "help"
|
185
|
+
help
|
186
|
+
next
|
187
|
+
when "sel"
|
188
|
+
if command[1]
|
189
|
+
sel = command[1].split(?.).map(&:to_i)
|
190
|
+
selected_transaction = nil
|
191
|
+
selected_functional_group = nil
|
192
|
+
selected_transaction_set = nil
|
193
|
+
selected_segment = nil
|
194
|
+
|
195
|
+
if sel[0] && get_transaction(transactions, sel[0])
|
196
|
+
selected_transaction = sel[0]
|
197
|
+
end
|
198
|
+
|
199
|
+
if sel[1] && get_functional_group(transactions, selected_transaction, sel[1])
|
200
|
+
selected_functional_group = sel[1]
|
201
|
+
end
|
202
|
+
|
203
|
+
if sel[2] && get_transaction_set(transactions, selected_transaction, selected_functional_group, sel[2])
|
204
|
+
selected_transaction_set = sel[2]
|
205
|
+
end
|
206
|
+
|
207
|
+
if sel[3] && get_segment(transactions, selected_transaction, selected_functional_group, selected_transaction_set, sel[3])
|
208
|
+
selected_segment = sel[3]
|
209
|
+
end
|
210
|
+
|
211
|
+
sel = [selected_transaction, selected_functional_group, selected_transaction_set, selected_segment]
|
212
|
+
sel.delete(nil)
|
213
|
+
STDOUT.puts "Selected #{sel.join(?.)}"
|
214
|
+
else
|
215
|
+
sel = [selected_transaction, selected_functional_group, selected_transaction_set, selected_segment]
|
216
|
+
sel.delete(nil)
|
217
|
+
STDOUT.puts sel.join(?.)
|
218
|
+
end
|
219
|
+
when "tx"
|
220
|
+
case command[1]
|
221
|
+
when "list"
|
222
|
+
list_transactions(transactions, selected_transaction)
|
223
|
+
when "sel"
|
224
|
+
if command[2].nil?
|
225
|
+
if selected_transaction.nil?
|
226
|
+
STDOUT.puts "No transaction selected"
|
227
|
+
else
|
228
|
+
STDOUT.puts "Transaction #{selected_transaction} selected"
|
229
|
+
end
|
230
|
+
else
|
231
|
+
txid = command[2].to_i
|
232
|
+
if transactions.to_a[txid]
|
233
|
+
selected_transaction = txid
|
234
|
+
selected_functional_group = nil
|
235
|
+
selected_transaction_set = nil
|
236
|
+
selected_segment = nil
|
237
|
+
STDOUT.puts "Transaction #{selected_transaction} selected"
|
238
|
+
else
|
239
|
+
STDERR.puts "Transaction #{txid} does not exist"
|
240
|
+
end
|
241
|
+
end
|
242
|
+
when "desel"
|
243
|
+
STDOUT.puts "Transaction #{selected_transaction} deselected"
|
244
|
+
selected_transaction = nil
|
245
|
+
selected_functional_group = nil
|
246
|
+
selected_transaction_set = nil
|
247
|
+
selected_segment = nil
|
248
|
+
when "load"
|
249
|
+
if command[2].nil? || !File.exist?(command[2])
|
250
|
+
STDERR.puts "File does not exist"
|
251
|
+
elsif transactions[command[2]]
|
252
|
+
STDERR.puts "Transaction already loaded"
|
253
|
+
else
|
254
|
+
transactions[command[2]] = RBEDI::Parser.new(File.read(command[2])).parse
|
255
|
+
selected_transaction = transactions.to_a.index([command[2], transactions[command[2]]])
|
256
|
+
selected_functional_group = nil
|
257
|
+
selected_transaction_set = nil
|
258
|
+
selected_segment = nil
|
259
|
+
end
|
260
|
+
when "unload"
|
261
|
+
if command[2].nil? || transactions.to_a[command[2].to_i].nil?
|
262
|
+
STDERR.puts "Transaction #{command[2]} does not exist"
|
263
|
+
else
|
264
|
+
transactions.delete(transactions.to_a[command[2].to_i][0])
|
265
|
+
if command[2].to_i == selected_transaction
|
266
|
+
selected_transaction = nil
|
267
|
+
selected_functional_group = nil
|
268
|
+
selected_transaction_set = nil
|
269
|
+
selected_segment = nil
|
270
|
+
elsif command[2].to_i < selected_transaction.to_i
|
271
|
+
selected_transaction -= 1
|
272
|
+
end
|
273
|
+
STDOUT.puts "Transaction #{command[2]} unloaded"
|
274
|
+
end
|
275
|
+
when "dup"
|
276
|
+
unless selected_transaction
|
277
|
+
STDERR.puts "No transaction selected"
|
278
|
+
next
|
279
|
+
end
|
280
|
+
|
281
|
+
unless command[2]
|
282
|
+
STDERR.puts "No file specified"
|
283
|
+
next
|
284
|
+
end
|
285
|
+
|
286
|
+
tx = get_transaction(transactions, selected_transaction)
|
287
|
+
duptx = tx.dup
|
288
|
+
dup_functional_groups(duptx)
|
289
|
+
|
290
|
+
transactions[command[2]] = duptx
|
291
|
+
selected_transaction = transactions.to_a.index([command[2], transactions[command[2]]])
|
292
|
+
when "new"
|
293
|
+
unless command[2]
|
294
|
+
STDERR.puts "No file specified"
|
295
|
+
next
|
296
|
+
end
|
297
|
+
|
298
|
+
transactions[command[2]] = RBEDI::TransactionEnvelope.new(
|
299
|
+
interchange_sender_id_qualifier: :mutually_defined,
|
300
|
+
interchange_sender_id: "",
|
301
|
+
interchange_receiver_id_qualifier: :mutually_defined,
|
302
|
+
interchange_receiver_id: "",
|
303
|
+
functional_groups: [],
|
304
|
+
interchange_control_number: 1,
|
305
|
+
date_time: DateTime.now,
|
306
|
+
repetition_separator: ?^,
|
307
|
+
component_element_separator: ?:,
|
308
|
+
interchange_usage_indicator: :production,
|
309
|
+
authorization_information_qualifier: :no_authorization_information_present,
|
310
|
+
authorization_information: " " * 10,
|
311
|
+
security_information_qualifier: :no_security_information_present,
|
312
|
+
security_information: " " * 10,
|
313
|
+
acknowledgement_requested: false
|
314
|
+
)
|
315
|
+
|
316
|
+
selected_transaction = transactions.to_a.index([command[2], transactions[command[2]]])
|
317
|
+
selected_functional_group = nil
|
318
|
+
selected_transaction_set = nil
|
319
|
+
selected_segment = nil
|
320
|
+
when "attr"
|
321
|
+
unless selected_transaction
|
322
|
+
STDERR.puts "No transaction selected"
|
323
|
+
next
|
324
|
+
end
|
325
|
+
if command[2].nil?
|
326
|
+
STDERR.puts "No attribute specified"
|
327
|
+
next
|
328
|
+
end
|
329
|
+
|
330
|
+
tx = get_transaction(transactions, selected_transaction)
|
331
|
+
|
332
|
+
case command[2]
|
333
|
+
when "interchange_sender_id_qualifier"
|
334
|
+
if command[3].nil?
|
335
|
+
STDOUT.puts tx.send(:interchange_sender_id_qualifier)
|
336
|
+
else
|
337
|
+
command[3] = command[3][1..-1].to_sym if command[3].start_with?(?:)
|
338
|
+
tx.send(:interchange_sender_id_qualifier=, command[3])
|
339
|
+
STDOUT.puts "interchange_sender_id_qualifier set to #{command[3]}"
|
340
|
+
end
|
341
|
+
when "interchange_sender_id"
|
342
|
+
if command[3].nil?
|
343
|
+
STDOUT.puts tx.send(:interchange_sender_id)
|
344
|
+
else
|
345
|
+
tx.send(:interchange_sender_id=, command[3])
|
346
|
+
STDOUT.puts "interchange_sender_id set to #{command[3]}"
|
347
|
+
end
|
348
|
+
when "interchange_receiver_id_qualifier"
|
349
|
+
if command[3].nil?
|
350
|
+
STDOUT.puts tx.send(:interchange_receiver_id_qualifier)
|
351
|
+
else
|
352
|
+
command[3] = command[3][1..-1].to_sym if command[3].start_with?(?:)
|
353
|
+
tx.send(:interchange_receiver_id_qualifier=, command[3])
|
354
|
+
STDOUT.puts "interchange_receiver_id_qualifier set to #{command[3]}"
|
355
|
+
end
|
356
|
+
when "interchange_receiver_id"
|
357
|
+
if command[3].nil?
|
358
|
+
STDOUT.puts tx.send(:interchange_receiver_id)
|
359
|
+
else
|
360
|
+
tx.send(:interchange_receiver_id=, command[3])
|
361
|
+
STDOUT.puts "interchange_receiver_id set to #{command[3]}"
|
362
|
+
end
|
363
|
+
when "interchange_control_number"
|
364
|
+
if command[3].nil?
|
365
|
+
STDOUT.puts tx.send(:interchange_control_number)
|
366
|
+
else
|
367
|
+
tx.send(:interchange_control_number=, command[3])
|
368
|
+
STDOUT.puts "interchange_control_number set to #{command[3]}"
|
369
|
+
end
|
370
|
+
when "date_time"
|
371
|
+
if command[3].nil?
|
372
|
+
STDOUT.print tx.send(:date_time).ccyymmdd
|
373
|
+
STDOUT.print " "
|
374
|
+
STDOUT.puts tx.send(:date_time).hhmmss
|
375
|
+
else
|
376
|
+
command[3] = command[3].split(" ")
|
377
|
+
datetime = RBEDI::EDIDateTime.parse(date: command[3][0], time: command[3][1])
|
378
|
+
tx.send(:date_time=, datetime)
|
379
|
+
STDOUT.puts "date_time set to #{command[3]}"
|
380
|
+
end
|
381
|
+
when "repetition_separator"
|
382
|
+
if command[3].nil?
|
383
|
+
STDOUT.puts tx.send(:repetition_separator)
|
384
|
+
else
|
385
|
+
tx.send(:repetition_separator=, command[3])
|
386
|
+
STDOUT.puts "repetition_separator set to #{command[3]}"
|
387
|
+
end
|
388
|
+
when "component_element_separator"
|
389
|
+
if command[3].nil?
|
390
|
+
STDOUT.puts tx.send(:component_element_separator)
|
391
|
+
else
|
392
|
+
tx.send(:component_element_separator=, command[3])
|
393
|
+
STDOUT.puts "component_element_separator set to #{command[3]}"
|
394
|
+
end
|
395
|
+
when "interchange_usage_indicator"
|
396
|
+
if command[3].nil?
|
397
|
+
STDOUT.puts tx.send(:interchange_usage_indicator)
|
398
|
+
else
|
399
|
+
command[3] = command[3][1..-1].to_sym if command[3].start_with?(?:)
|
400
|
+
tx.send(:interchange_usage_indicator=, command[3])
|
401
|
+
STDOUT.puts "interchange_usage_indicator set to #{command[3]}"
|
402
|
+
end
|
403
|
+
when "authorization_information_qualifier"
|
404
|
+
if command[3].nil?
|
405
|
+
STDOUT.puts tx.send(:authorization_information_qualifier)
|
406
|
+
else
|
407
|
+
command[3] = command[3][1..-1].to_sym if command[3].start_with?(?:)
|
408
|
+
tx.send(:authorization_information_qualifier=, command[3])
|
409
|
+
STDOUT.puts "authorization_information_qualifier set to #{command[3]}"
|
410
|
+
end
|
411
|
+
when "authorization_information"
|
412
|
+
if command[3].nil?
|
413
|
+
STDOUT.puts tx.send(:authorization_information)
|
414
|
+
else
|
415
|
+
tx.send(:authorization_information=, command[3])
|
416
|
+
STDOUT.puts "authorization_information set to #{command[3]}"
|
417
|
+
end
|
418
|
+
when "security_information_qualifier"
|
419
|
+
if command[3].nil?
|
420
|
+
STDOUT.puts tx.send(:security_information_qualifier)
|
421
|
+
else
|
422
|
+
command[3] = command[3][1..-1].to_sym if command[3].start_with?(?:)
|
423
|
+
tx.send(:security_information_qualifier=, command[3])
|
424
|
+
STDOUT.puts "security_information_qualifier set to #{command[3]}"
|
425
|
+
end
|
426
|
+
when "security_information"
|
427
|
+
if command[3].nil?
|
428
|
+
STDOUT.puts tx.send(:security_information)
|
429
|
+
else
|
430
|
+
tx.send(:security_information=, command[3])
|
431
|
+
STDOUT.puts "security_information set to #{command[3]}"
|
432
|
+
end
|
433
|
+
when "acknowledgement_requested"
|
434
|
+
if command[3].nil?
|
435
|
+
STDOUT.puts tx.send(:acknowledgement_requested)
|
436
|
+
else
|
437
|
+
command[3] = true if command[3] == "true"
|
438
|
+
command[3] = false if command[3] == "false"
|
439
|
+
tx.send(:acknowledgement_requested=, command[3])
|
440
|
+
STDOUT.puts "acknowledgement_requested set to #{command[3]}"
|
441
|
+
end
|
442
|
+
else
|
443
|
+
STDERR.puts "Invalid attribute"
|
444
|
+
end
|
445
|
+
when "write"
|
446
|
+
if selected_transaction.nil?
|
447
|
+
STDERR.puts "No transaction selected"
|
448
|
+
else
|
449
|
+
filename = transactions.to_a[selected_transaction][0]
|
450
|
+
File.write(filename, get_transaction(transactions, selected_transaction).to_s)
|
451
|
+
STDOUT.puts "#{filename} written"
|
452
|
+
end
|
453
|
+
else
|
454
|
+
STDERR.puts "Invalid command"
|
455
|
+
end
|
456
|
+
when "fg"
|
457
|
+
unless selected_transaction
|
458
|
+
STDERR.puts "No transaction selected"
|
459
|
+
next
|
460
|
+
end
|
461
|
+
|
462
|
+
case command[1]
|
463
|
+
when "list"
|
464
|
+
list_functional_groups(get_transaction(transactions, selected_transaction), selected_functional_group)
|
465
|
+
when "sel"
|
466
|
+
if command[2].nil?
|
467
|
+
if selected_functional_group.nil?
|
468
|
+
STDOUT.puts "No functional group selected"
|
469
|
+
else
|
470
|
+
STDOUT.puts "Functional group #{selected_functional_group} selected"
|
471
|
+
end
|
472
|
+
else
|
473
|
+
fgid = command[2].to_i
|
474
|
+
if get_functional_group(transactions, selected_transaction, fgid)
|
475
|
+
selected_functional_group = fgid
|
476
|
+
selected_transaction_set = nil
|
477
|
+
selected_segment = nil
|
478
|
+
STDOUT.puts "Functional group #{selected_functional_group} selected"
|
479
|
+
else
|
480
|
+
STDERR.puts "Functional group #{fgid} does not exist"
|
481
|
+
end
|
482
|
+
end
|
483
|
+
when "desel"
|
484
|
+
STDOUT.puts "Functional group #{selected_functional_group} deselected"
|
485
|
+
selected_functional_group = nil
|
486
|
+
selected_transaction_set = nil
|
487
|
+
selected_segment = nil
|
488
|
+
when "dup"
|
489
|
+
unless selected_functional_group
|
490
|
+
STDERR.puts "No functional group selected"
|
491
|
+
next
|
492
|
+
end
|
493
|
+
|
494
|
+
tx = get_transaction(transactions, selected_transaction)
|
495
|
+
fg = get_functional_group(transactions, selected_transaction, selected_functional_group)
|
496
|
+
dupfg = fg.dup
|
497
|
+
dup_transaction_sets(dupfg)
|
498
|
+
|
499
|
+
if command[2]
|
500
|
+
tx.functional_groups.insert(command[2].to_i, dupfg)
|
501
|
+
else
|
502
|
+
tx.functional_groups << dupfg
|
503
|
+
end
|
504
|
+
|
505
|
+
selected_functional_group = tx.functional_groups.index(dupfg)
|
506
|
+
when "new"
|
507
|
+
tx = get_transaction(transactions, selected_transaction)
|
508
|
+
maxnum = tx.functional_groups.map{|g|g.group_control_number.to_i}.max.to_i
|
509
|
+
fg = RBEDI::FunctionalGroup.new(
|
510
|
+
group_control_number: maxnum+1,
|
511
|
+
functional_identifier_code: "",
|
512
|
+
application_sender_code: "",
|
513
|
+
application_receiver_code: "",
|
514
|
+
date_time: DateTime.now,
|
515
|
+
)
|
516
|
+
|
517
|
+
if command[2]
|
518
|
+
tx.functional_groups.insert(command[2].to_i, fg)
|
519
|
+
else
|
520
|
+
tx.functional_groups << fg
|
521
|
+
end
|
522
|
+
|
523
|
+
selected_functional_group = tx.functional_groups.index(fg)
|
524
|
+
selected_transaction_set = nil
|
525
|
+
selected_segment = nil
|
526
|
+
when "del"
|
527
|
+
fgid = command[2].to_i
|
528
|
+
tx = get_transaction(transactions, selected_transaction)
|
529
|
+
fg = get_functional_group(transactions, selected_transaction, fgid)
|
530
|
+
unless fg
|
531
|
+
STDERR.puts "Functional group #{fgid} does not exist"
|
532
|
+
end
|
533
|
+
if selected_functional_group == fgid
|
534
|
+
selected_functional_group = nil
|
535
|
+
selected_transaction_set = nil
|
536
|
+
selected_segment = nil
|
537
|
+
elsif fgid < selected_functional_group.to_i
|
538
|
+
selected_functional_group -= 1
|
539
|
+
end
|
540
|
+
tx.functional_groups.delete(fg)
|
541
|
+
STDOUT.puts "Functional group #{fgid} deleted"
|
542
|
+
when "attr"
|
543
|
+
unless selected_functional_group
|
544
|
+
STDERR.puts "No functional group selected"
|
545
|
+
next
|
546
|
+
end
|
547
|
+
if command[2].nil?
|
548
|
+
STDERR.puts "No attribute specified"
|
549
|
+
next
|
550
|
+
end
|
551
|
+
|
552
|
+
fg = get_functional_group(transactions, selected_transaction, selected_functional_group)
|
553
|
+
|
554
|
+
case command[2]
|
555
|
+
when "functional_identifier_code"
|
556
|
+
if command[3].nil?
|
557
|
+
STDOUT.puts fg.send(:functional_identifier_code)
|
558
|
+
else
|
559
|
+
command[3] = command[3][1..-1].to_sym if command[3].start_with?(?:)
|
560
|
+
fg.send(:functional_identifier_code=, command[3])
|
561
|
+
STDOUT.puts "functional_identifier_code set to #{command[3]}"
|
562
|
+
end
|
563
|
+
when "application_sender_code"
|
564
|
+
if command[3].nil?
|
565
|
+
STDOUT.puts fg.send(:application_sender_code)
|
566
|
+
else
|
567
|
+
fg.send(:application_sender_code=, command[3])
|
568
|
+
STDOUT.puts "application_sender_code set to #{command[3]}"
|
569
|
+
end
|
570
|
+
when "application_receiver_code"
|
571
|
+
if command[3].nil?
|
572
|
+
STDOUT.puts fg.send(:application_receiver_code)
|
573
|
+
else
|
574
|
+
fg.send(:application_receiver_code=, command[3])
|
575
|
+
STDOUT.puts "application_receiver_code set to #{command[3]}"
|
576
|
+
end
|
577
|
+
when "group_control_number"
|
578
|
+
if command[3].nil?
|
579
|
+
STDOUT.puts fg.send(:group_control_number)
|
580
|
+
else
|
581
|
+
fg.send(:group_control_number=, command[3])
|
582
|
+
STDOUT.puts "group_control_number set to #{command[3]}"
|
583
|
+
end
|
584
|
+
when "date_time"
|
585
|
+
if command[3].nil?
|
586
|
+
STDOUT.print fg.send(:date_time).ccyymmdd
|
587
|
+
STDOUT.print " "
|
588
|
+
STDOUT.puts fg.send(:date_time).hhmmss
|
589
|
+
else
|
590
|
+
command[3] = command[3].split(" ")
|
591
|
+
datetime = RBEDI::EDIDateTime.parse(date: command[3][0], time: command[3][1])
|
592
|
+
fg.send(:date_time=, datetime)
|
593
|
+
STDOUT.puts "date_time set to #{command[3]}"
|
594
|
+
end
|
595
|
+
else
|
596
|
+
STDERR.puts "Invalid attribute"
|
597
|
+
end
|
598
|
+
else
|
599
|
+
STDERR.puts "Invalid command"
|
600
|
+
end
|
601
|
+
when "ts"
|
602
|
+
unless selected_functional_group
|
603
|
+
STDERR.puts "No functional group selected"
|
604
|
+
next
|
605
|
+
end
|
606
|
+
|
607
|
+
case command[1]
|
608
|
+
when "list"
|
609
|
+
list_transaction_sets(get_functional_group(transactions, selected_transaction, selected_functional_group), selected_transaction_set)
|
610
|
+
when "sel"
|
611
|
+
if command[2].nil?
|
612
|
+
if selected_transaction_set.nil?
|
613
|
+
STDOUT.puts "No transaction set selected"
|
614
|
+
else
|
615
|
+
STDOUT.puts "Transaction set #{selected_transaction_set} selected"
|
616
|
+
end
|
617
|
+
else
|
618
|
+
tsid = command[2].to_i
|
619
|
+
if get_transaction_set(transactions, selected_transaction, selected_functional_group, tsid)
|
620
|
+
selected_transaction_set = tsid
|
621
|
+
selected_segment = nil
|
622
|
+
STDOUT.puts "Transaction set #{selected_transaction_set} selected"
|
623
|
+
else
|
624
|
+
STDERR.puts "Transaction set #{tsid} does not exist"
|
625
|
+
end
|
626
|
+
end
|
627
|
+
when "desel"
|
628
|
+
STDOUT.puts "Transaction set #{selected_transaction_set} deselected"
|
629
|
+
selected_transaction_set = nil
|
630
|
+
selected_segment = nil
|
631
|
+
when "dup"
|
632
|
+
unless selected_transaction_set
|
633
|
+
STDERR.puts "No transaction set selected"
|
634
|
+
next
|
635
|
+
end
|
636
|
+
|
637
|
+
fg = get_functional_group(transactions, selected_transaction, selected_functional_group)
|
638
|
+
ts = get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set)
|
639
|
+
dupts = ts.dup
|
640
|
+
dup_segments(dupts)
|
641
|
+
|
642
|
+
if command[2]
|
643
|
+
fg.transaction_sets.insert(command[2].to_i, dupts)
|
644
|
+
else
|
645
|
+
fg.transaction_sets << dupts
|
646
|
+
end
|
647
|
+
|
648
|
+
selected_transaction_set = fg.transaction_sets.index(dupts)
|
649
|
+
when "new"
|
650
|
+
fg = get_functional_group(transactions, selected_transaction, selected_functional_group)
|
651
|
+
maxnum = fg.transaction_sets.map{|s|s.transaction_set_control_number.to_i}.max.to_i
|
652
|
+
ts = RBEDI::TransactionSet.new(
|
653
|
+
transaction_set_control_number: maxnum+1,
|
654
|
+
transaction_set_identifier_code: "",
|
655
|
+
)
|
656
|
+
|
657
|
+
if command[2]
|
658
|
+
fg.transaction_sets.insert(command[2].to_i, ts)
|
659
|
+
else
|
660
|
+
fg.transaction_sets << ts
|
661
|
+
end
|
662
|
+
|
663
|
+
selected_transaction_set = fg.transaction_sets.index(ts)
|
664
|
+
selected_segment = nil
|
665
|
+
when "del"
|
666
|
+
tsid = command[2].to_i
|
667
|
+
fg = get_functional_group(transactions, selected_transaction, selected_functional_group)
|
668
|
+
ts = get_transaction_set(transactions, selected_transaction, selected_functional_group, tsid)
|
669
|
+
unless ts
|
670
|
+
STDERR.puts "Transaction set #{tsid} does not exist"
|
671
|
+
end
|
672
|
+
if selected_transaction_set == tsid
|
673
|
+
selected_transaction_set = nil
|
674
|
+
selected_segment = nil
|
675
|
+
elsif tsid < selected_transaction_set.to_i
|
676
|
+
selected_transaction_set -= 1
|
677
|
+
end
|
678
|
+
fg.transaction_sets.delete(ts)
|
679
|
+
STDOUT.puts "Transaction set #{tsid} deleted"
|
680
|
+
when "attr"
|
681
|
+
unless selected_transaction_set
|
682
|
+
STDERR.puts "No transaction set selected"
|
683
|
+
next
|
684
|
+
end
|
685
|
+
if command[2].nil?
|
686
|
+
STDERR.puts "No attribute specified"
|
687
|
+
next
|
688
|
+
end
|
689
|
+
|
690
|
+
ts = get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set)
|
691
|
+
|
692
|
+
case command[2]
|
693
|
+
when "transaction_set_identifier_code"
|
694
|
+
if command[3].nil?
|
695
|
+
STDOUT.puts ts.send(:transaction_set_identifier_code)
|
696
|
+
else
|
697
|
+
command[3] = command[3][1..-1].to_sym if command[3].start_with?(?:)
|
698
|
+
ts.send(:transaction_set_identifier_code=, command[3])
|
699
|
+
STDOUT.puts "transaction_set_identifier_code set to #{command[3]}"
|
700
|
+
end
|
701
|
+
when "transaction_set_control_number"
|
702
|
+
if command[3].nil?
|
703
|
+
STDOUT.puts ts.send(:transaction_set_control_number)
|
704
|
+
else
|
705
|
+
ts.send(:transaction_set_control_number=, command[3])
|
706
|
+
STDOUT.puts "transaction_set_control_number set to #{command[3]}"
|
707
|
+
end
|
708
|
+
else
|
709
|
+
STDERR.puts "Invalid attribute"
|
710
|
+
end
|
711
|
+
else
|
712
|
+
STDERR.puts "Invalid command"
|
713
|
+
end
|
714
|
+
when "sg"
|
715
|
+
unless selected_transaction_set
|
716
|
+
STDERR.puts "No transaction set selected"
|
717
|
+
next
|
718
|
+
end
|
719
|
+
|
720
|
+
case command[1]
|
721
|
+
when "list"
|
722
|
+
range = nil
|
723
|
+
if command[2]
|
724
|
+
rstart = command[2].to_i
|
725
|
+
rend = command[3] ? command[3].to_i : rstart
|
726
|
+
|
727
|
+
range = (rstart..rend)
|
728
|
+
end
|
729
|
+
|
730
|
+
list_segments(get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set), selected_segment, range: range)
|
731
|
+
when "fil"
|
732
|
+
unless command[2]
|
733
|
+
STDERR.puts "No type specified"
|
734
|
+
next
|
735
|
+
end
|
736
|
+
command[2] = command[2][1..-1].to_sym if command[2].start_with?(?:)
|
737
|
+
if command[2].is_a?(Symbol)
|
738
|
+
command[2] = RBEDI::Codes::SegmentNames.segment_name(command[2])
|
739
|
+
end
|
740
|
+
list_segments(get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set), selected_segment, filter: command[2])
|
741
|
+
when "search"
|
742
|
+
unless command[2]
|
743
|
+
STDERR.puts "No search query specified"
|
744
|
+
next
|
745
|
+
end
|
746
|
+
list_segments(get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set), selected_segment, search: command[2])
|
747
|
+
when "sel"
|
748
|
+
if command[2].nil?
|
749
|
+
if selected_segment.nil?
|
750
|
+
STDOUT.puts "No segment selected"
|
751
|
+
else
|
752
|
+
STDOUT.puts "Segment #{selected_segment} selected"
|
753
|
+
end
|
754
|
+
else
|
755
|
+
sgid = command[2].to_i
|
756
|
+
if get_segment(transactions, selected_transaction, selected_functional_group, selected_transaction_set, sgid)
|
757
|
+
selected_segment = sgid
|
758
|
+
STDOUT.puts "Segment #{selected_segment} selected"
|
759
|
+
else
|
760
|
+
STDERR.puts "Segment #{sgid} does not exist"
|
761
|
+
end
|
762
|
+
end
|
763
|
+
when "desel"
|
764
|
+
STDOUT.puts "Segment #{selected_segment} deselected"
|
765
|
+
selected_segment = nil
|
766
|
+
when "dup"
|
767
|
+
unless selected_segment
|
768
|
+
STDERR.puts "No segment selected"
|
769
|
+
next
|
770
|
+
end
|
771
|
+
|
772
|
+
ts = get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set)
|
773
|
+
sg = get_segment(transactions, selected_transaction, selected_functional_group, selected_transaction_set, selected_segment)
|
774
|
+
dupsg = sg.dup
|
775
|
+
dup_strings(dupsg)
|
776
|
+
|
777
|
+
if command[2]
|
778
|
+
ts.segments.insert(command[2].to_i, dupsg)
|
779
|
+
else
|
780
|
+
ts.segments << dupsg
|
781
|
+
end
|
782
|
+
|
783
|
+
selected_segment = ts.segments.index(dupsg)
|
784
|
+
when "new"
|
785
|
+
unless command[2]
|
786
|
+
STDERR.puts "Segment type not specified"
|
787
|
+
next
|
788
|
+
else
|
789
|
+
command[2] = command[2][1..-1].to_sym if command[2].start_with?(?:)
|
790
|
+
end
|
791
|
+
|
792
|
+
ts = get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set)
|
793
|
+
sg = RBEDI::Segment.new(
|
794
|
+
command[2],
|
795
|
+
_separator: repetition_separator(transactions, selected_transaction)
|
796
|
+
)
|
797
|
+
|
798
|
+
if command[3]
|
799
|
+
ts.segments.insert(command[3].to_i, sg)
|
800
|
+
else
|
801
|
+
ts.segments << sg
|
802
|
+
end
|
803
|
+
|
804
|
+
selected_segment = ts.segments.index(sg)
|
805
|
+
when "del"
|
806
|
+
sgid = command[2].to_i
|
807
|
+
ts = get_transaction_set(transactions, selected_transaction, selected_functional_group, selected_transaction_set)
|
808
|
+
sg = get_segment(transactions, selected_transaction, selected_functional_group, selected_transaction_set, sgid)
|
809
|
+
unless sg
|
810
|
+
STDERR.puts "Segment #{sgid} does not exist"
|
811
|
+
end
|
812
|
+
if selected_segment == sgid
|
813
|
+
selected_segment = nil
|
814
|
+
elsif sgid < selected_segment.to_i
|
815
|
+
selected_segment -= 1
|
816
|
+
end
|
817
|
+
ts.segments.delete(sg)
|
818
|
+
STDOUT.puts "Segment #{sgid} deleted"
|
819
|
+
when "attr"
|
820
|
+
unless selected_segment
|
821
|
+
STDERR.puts "No segment selected"
|
822
|
+
next
|
823
|
+
end
|
824
|
+
if command[2].nil?
|
825
|
+
STDERR.puts "No attribute specified"
|
826
|
+
next
|
827
|
+
end
|
828
|
+
|
829
|
+
sg = get_segment(transactions, selected_transaction, selected_functional_group, selected_transaction_set, selected_segment)
|
830
|
+
|
831
|
+
if command[2] == "type"
|
832
|
+
STDOUT.puts sg.send(:segment_type)
|
833
|
+
elsif command[2] == "separator"
|
834
|
+
STDOUT.puts sg.send(:separator)
|
835
|
+
elsif !command[2].match?(/[0-9]/)
|
836
|
+
command[2] = command[2].to_sym
|
837
|
+
if command[3]
|
838
|
+
command[3] = command[3].split(/,[\s]?/)
|
839
|
+
command[3].map! do |i|
|
840
|
+
if i.start_with?(?:)
|
841
|
+
i[1..-1].to_sym
|
842
|
+
elsif i == "b:true"
|
843
|
+
true
|
844
|
+
elsif i == "b:false"
|
845
|
+
false
|
846
|
+
else
|
847
|
+
i
|
848
|
+
end
|
849
|
+
end
|
850
|
+
sg[command[2]] = command[3]
|
851
|
+
STDOUT.puts "#{command[2]} set to #{command[3].join(sg.separator)}"
|
852
|
+
else
|
853
|
+
e = sg[command[2]]
|
854
|
+
if e.is_a?(Array)
|
855
|
+
STDOUT.puts e.join(", ")
|
856
|
+
else
|
857
|
+
STDOUT.puts e
|
858
|
+
end
|
859
|
+
end
|
860
|
+
elsif command[2].match(/^[0-9]*$/)
|
861
|
+
command[2] = command[2].to_i
|
862
|
+
if command[3]
|
863
|
+
command[3] = command[3].split(/,[\s]?/)
|
864
|
+
command[3].map! do |i|
|
865
|
+
if i.start_with?(?:)
|
866
|
+
i[1..-1].to_sym
|
867
|
+
elsif i == "b:true"
|
868
|
+
true
|
869
|
+
elsif i == "b:false"
|
870
|
+
false
|
871
|
+
else
|
872
|
+
i
|
873
|
+
end
|
874
|
+
end
|
875
|
+
sg[command[2]] = command[3]
|
876
|
+
STDOUT.puts "#{command[2]} set to #{command[3].join(sg.separator)}"
|
877
|
+
else
|
878
|
+
e = sg[command[2]]
|
879
|
+
if e.is_a?(Array)
|
880
|
+
STDOUT.puts e.join(", ")
|
881
|
+
else
|
882
|
+
STDOUT.puts e
|
883
|
+
end
|
884
|
+
end
|
885
|
+
end
|
886
|
+
else
|
887
|
+
STDERR.puts "Invalid command"
|
888
|
+
end
|
889
|
+
when "exit"
|
890
|
+
exit
|
891
|
+
else
|
892
|
+
STDERR.puts "Invalid command"
|
893
|
+
end
|
894
|
+
rescue => e
|
895
|
+
raise e if args.options[:"raise-errors"]
|
896
|
+
end
|
897
|
+
end
|