zaphire 0.0.18 → 0.0.36
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/zaphire.rb +582 -507
- data/test/test_zaphire.rb +0 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 490649dca97a57ebd6112acb99f9a9c727eafd60
|
4
|
+
data.tar.gz: df8c16f18ae82d1f781f8e2502879dc744040aa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb593e631383b0ad495e96b47c63a785a89640a9136a0e0ec1eb12584898c40816b04efb075802784a10431018b0e9d0c9a7747369cfa03f9aa4a1449c9a5daf
|
7
|
+
data.tar.gz: ceb6827ea60b4e404c3d378e11c85276dab09714ccc76ec6bb01a4c986cb11f54b16fe6dcf694450c8ca4ff5122dec8b1c2b1f69695046b09420b53c515f19c6
|
data/lib/zaphire.rb
CHANGED
@@ -1,507 +1,582 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
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
|
-
end
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
#
|
373
|
-
#
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
end
|
502
|
-
|
503
|
-
def
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
1
|
+
# enconding: utf-8
|
2
|
+
require 'roo'
|
3
|
+
# require 'google-spreadsheet-ruby'
|
4
|
+
require 'matrix'
|
5
|
+
require 'google_drive'
|
6
|
+
require 'csv'
|
7
|
+
require 'open-uri'
|
8
|
+
|
9
|
+
# short version for short commands that rely on global variable well set to get things
|
10
|
+
|
11
|
+
module Z
|
12
|
+
def self.get(p = @iivar, _isHash = false)
|
13
|
+
begin
|
14
|
+
session = GoogleDrive.login_with_oauth(p['auth_token']) unless p['auth_token'].nil?
|
15
|
+
session = GoogleDrive.login(p['user'], p['password'])
|
16
|
+
|
17
|
+
ws = session.spreadsheet_by_key(p['key']).worksheet_by_title(p['sheet'])
|
18
|
+
|
19
|
+
value = ws[p['y'], p['x']]
|
20
|
+
p = eval(value)
|
21
|
+
p = nil if p[p.length - 1][0] != '<gpackend>'
|
22
|
+
p.delete_last_item
|
23
|
+
rescue
|
24
|
+
return nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.v
|
29
|
+
'36'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Zsave
|
34
|
+
def self.csv(arr, file, mode = 'w', _opts = {})
|
35
|
+
arr = arr.to_a
|
36
|
+
|
37
|
+
File.open(file, mode) { |f| f << arr.map(&:to_csv).join("\n") }
|
38
|
+
|
39
|
+
# open(path,mode,opts){ |csv| array.each{ |row| csv << row } }
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.cvs(_array, _path, mode = 'w', _opts = {})
|
43
|
+
arr = arr.to_a
|
44
|
+
|
45
|
+
File.open(file, mode) { |f| f << arr.map(&:to_csv).join("\n") }
|
46
|
+
|
47
|
+
# open(path,mode,opts){ |csv| array.each{ |row| csv << row } }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Zgdocs
|
52
|
+
def self.addvalue(key, sheet, value, user, password)
|
53
|
+
t = Roo::Google.new(key, user: user, password: password)
|
54
|
+
t.default_sheet = sheet
|
55
|
+
|
56
|
+
rowtosave = Zgdocs.nextemptyrow(key, sheet, user, password)
|
57
|
+
|
58
|
+
t.set(rowtosave, 1, value, sheet)
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.addvaluenoaddrow(key, sheet, value, user, password)
|
62
|
+
t = Roo::Google.new(key, user: user, password: password)
|
63
|
+
t.default_sheet = sheet
|
64
|
+
|
65
|
+
rowtosave = t.last_row + 1
|
66
|
+
|
67
|
+
t.set(rowtosave, 1, value, sheet)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.addvaluenoaddrowtoken(key, sheet, value, _user, _password, token)
|
71
|
+
session = GoogleDrive.login_with_oauth(token)
|
72
|
+
|
73
|
+
ws = session.spreadsheet_by_key(key).worksheet_by_title(sheet)
|
74
|
+
|
75
|
+
row = ws[1, 1]
|
76
|
+
|
77
|
+
ws[row, 1] = value
|
78
|
+
ws.save
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.nextemptyrow(key, sheet, user, password)
|
82
|
+
t = Roo::Google.new(key, user: user, password: password)
|
83
|
+
t.default_sheet = sheet
|
84
|
+
|
85
|
+
session = GoogleDrive.login(user, password)
|
86
|
+
ws = session.spreadsheet_by_key(key).worksheet_by_title(sheet)
|
87
|
+
|
88
|
+
rows = t.last_row
|
89
|
+
|
90
|
+
ws.max_rows = (rows + 1) if ws.max_rows == rows
|
91
|
+
|
92
|
+
rows = 0 if rows.nil?
|
93
|
+
|
94
|
+
aa = rows + 1
|
95
|
+
aa
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.save(key, sheet, startcel, data, user, password)
|
99
|
+
t = Roo::Google.new(key, user: user, password: password)
|
100
|
+
t.default_sheet = sheet
|
101
|
+
|
102
|
+
rowstart = startcel[0]
|
103
|
+
colstart = startcel[1]
|
104
|
+
|
105
|
+
curRow = rowstart
|
106
|
+
|
107
|
+
rowstosave = data.row_size
|
108
|
+
sheetrows = Zgdocs.makesurethereisrows(rowstosave, key, sheet, user, password)
|
109
|
+
|
110
|
+
puts 'Data to save: ' << data.to_s
|
111
|
+
puts 'Rows : ' << rowstosave.to_s
|
112
|
+
|
113
|
+
xx = data.row_size - 1
|
114
|
+
|
115
|
+
0.upto(xx) do |therow|
|
116
|
+
|
117
|
+
curCol = colstart
|
118
|
+
|
119
|
+
m 'ZgdocsSaving Row', therow, xx
|
120
|
+
|
121
|
+
data.row(therow).each do |value|
|
122
|
+
|
123
|
+
# 0.upto(row.column_count) do |col|
|
124
|
+
|
125
|
+
# puts "ZgdocsSaving row: " << curRow.to_s << " col: " << curCol.to_s << " Value: " << value.to_s
|
126
|
+
|
127
|
+
# value = data[rownum,colnum]
|
128
|
+
|
129
|
+
t.set(curRow, curCol, value, sheet)
|
130
|
+
|
131
|
+
curCol += 1
|
132
|
+
end
|
133
|
+
|
134
|
+
curRow += 1
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def self.makesurethereisrows(rows, key, sheet, user, password)
|
140
|
+
t = Roo::Google.new(key, user: user, password: password)
|
141
|
+
|
142
|
+
session = GoogleDrive.login(user, password)
|
143
|
+
|
144
|
+
ws = session.spreadsheet_by_key(key).worksheet_by_title(sheet)
|
145
|
+
|
146
|
+
ws.max_rows = (rows + 2) if ws.max_rows < rows
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.makesurethereissheet(sheet, key, user, password)
|
150
|
+
t = Roo::Google.new(key, user: user, password: password)
|
151
|
+
|
152
|
+
unless t.sheets.include?(sheet)
|
153
|
+
session = GoogleDrive.login(user, password)
|
154
|
+
ws = session.spreadsheet_by_key(key)
|
155
|
+
worksheet = ws.add_worksheet(sheet)
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
def it
|
161
|
+
@it
|
162
|
+
end
|
163
|
+
|
164
|
+
def get(a = '')
|
165
|
+
@it = a
|
166
|
+
end
|
167
|
+
|
168
|
+
def trunc(a, decimals = 0)
|
169
|
+
if decimals == 0
|
170
|
+
a.to_i
|
171
|
+
else
|
172
|
+
b = '%.' << decimals << 'f'
|
173
|
+
sprintf(b, a)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def put(a)
|
178
|
+
puts a.to_s
|
179
|
+
end
|
180
|
+
|
181
|
+
def d(itext, i = nil, xx = '', iadditional = '')
|
182
|
+
if i.nil?
|
183
|
+
puts itext
|
184
|
+
return ''
|
185
|
+
else
|
186
|
+
iadditional = '' if iadditional.nil?
|
187
|
+
tt = xx.to_f + 1.00
|
188
|
+
aa = trunc((( (i.to_f + 1) / tt) * 100))
|
189
|
+
it = itext << ': (' << aa.to_s << '%)'
|
190
|
+
|
191
|
+
return '' if @mvar == it
|
192
|
+
@mvar = it
|
193
|
+
|
194
|
+
texttodisp = @mvar << ' ' << iadditional
|
195
|
+
|
196
|
+
i += 1
|
197
|
+
xx += 1
|
198
|
+
|
199
|
+
@mstart = theticks if i == 1
|
200
|
+
return '' if i == 1 || xx == 1
|
201
|
+
|
202
|
+
it = trunc((i.to_f / tt * 10))
|
203
|
+
|
204
|
+
ee = ( (theticks.to_f - @mstart.to_f) / 60) * ( (tt - i) / i.to_f)
|
205
|
+
aa = trunc(ee)
|
206
|
+
bb = trunc(aa.to_f / 60)
|
207
|
+
cc1 = aa.to_f / 60
|
208
|
+
cc2 = trunc((aa.to_f / 60))
|
209
|
+
cc = trunc((cc1 - cc2) * 60)
|
210
|
+
|
211
|
+
cc = '0' << cc.to_s if cc.to_s.size == 1
|
212
|
+
|
213
|
+
it = '[' << ' XXXXXXXXXX'[1..it.to_i] << ' __________'[1..(10 - it.to_i)] << '] ' << texttodisp << ' (' << bb.to_s << ':' << cc.to_s << ' Min. left) ' << i.to_i.to_s << ' of ' << tt.to_i.to_s
|
214
|
+
|
215
|
+
d it
|
216
|
+
|
217
|
+
iSetMsgForTerm(@itermattended, it) unless @itermattended
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def iSetMsgForTerm(_iterm, _imessage)
|
222
|
+
''
|
223
|
+
end
|
224
|
+
|
225
|
+
def theticks
|
226
|
+
Time.now.to_i
|
227
|
+
end
|
228
|
+
|
229
|
+
# Extending Ruby !!
|
230
|
+
|
231
|
+
class String
|
232
|
+
def delete_lines(num_of_lines = 1)
|
233
|
+
return '' if self == ''
|
234
|
+
split(/\r\n|\r|\n/, num_of_lines + 1).last
|
235
|
+
end
|
236
|
+
|
237
|
+
def delete_char(number = 1, number2 = '')
|
238
|
+
return '' if self == ''
|
239
|
+
if number2 == ''
|
240
|
+
self[number - 1] = ''
|
241
|
+
self
|
242
|
+
else
|
243
|
+
self[number - 1..number2 - 1] = ''
|
244
|
+
self
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def char(number = 1, number2 = '')
|
249
|
+
return '' if self == ''
|
250
|
+
if number2 == ''
|
251
|
+
self[number - 1]
|
252
|
+
else
|
253
|
+
self[number - 1..number2 - 1]
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
def line(number = 1, number2 = '')
|
258
|
+
return '' if self == ''
|
259
|
+
if number2 == ''
|
260
|
+
ok.split("\n")[number - 1]
|
261
|
+
else
|
262
|
+
ok.split("\n")[number - 1..number2 - 1]
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def contains(tofind)
|
267
|
+
return false if self == ''
|
268
|
+
self.include? tofind
|
269
|
+
end
|
270
|
+
|
271
|
+
def lastchar(a = 1)
|
272
|
+
return '' if self == ''
|
273
|
+
self[-a..-1]
|
274
|
+
end
|
275
|
+
|
276
|
+
def number_of_lines
|
277
|
+
return 0 if self == ''
|
278
|
+
lines.count
|
279
|
+
end
|
280
|
+
|
281
|
+
def ok
|
282
|
+
force_encoding('UTF-8')
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
class Array
|
287
|
+
def delete_last_item(n = 1)
|
288
|
+
take size - n
|
289
|
+
end
|
290
|
+
|
291
|
+
def lastitem
|
292
|
+
self[-1]
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
class NilClass
|
297
|
+
def lastchar
|
298
|
+
''
|
299
|
+
end
|
300
|
+
|
301
|
+
def ok
|
302
|
+
''.force_encoding('UTF-8')
|
303
|
+
end
|
304
|
+
|
305
|
+
def number_of_lines
|
306
|
+
0
|
307
|
+
end
|
308
|
+
|
309
|
+
def contains
|
310
|
+
false
|
311
|
+
end
|
312
|
+
|
313
|
+
def line
|
314
|
+
''
|
315
|
+
end
|
316
|
+
|
317
|
+
def lines
|
318
|
+
''
|
319
|
+
end
|
320
|
+
|
321
|
+
def char
|
322
|
+
''
|
323
|
+
end
|
324
|
+
|
325
|
+
def delete_char(_number = 1, _number2 = '')
|
326
|
+
''
|
327
|
+
end
|
328
|
+
|
329
|
+
def delete_lines(_num_of_lines = 1)
|
330
|
+
''
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
class Matrix
|
335
|
+
def dump(firstLine = '')
|
336
|
+
str = ''
|
337
|
+
if firstLine != ''
|
338
|
+
str << firstLine << "\n"
|
339
|
+
end
|
340
|
+
for i in 0...row_size
|
341
|
+
space = ''
|
342
|
+
for j in 0...column_size
|
343
|
+
str << space << self[i, j].to_s
|
344
|
+
space = ' '
|
345
|
+
end
|
346
|
+
str << "\n"
|
347
|
+
end
|
348
|
+
str
|
349
|
+
end
|
350
|
+
# La classe Matrix est immutable, or je veux pouvoir écrire :
|
351
|
+
# m[i,j] = v
|
352
|
+
#
|
353
|
+
def []=(i, j, v)
|
354
|
+
@rows[i][j] = v
|
355
|
+
end
|
356
|
+
# Il n'y a même pas de constructeur pour une matrice rectangulaire : bouhhh
|
357
|
+
# Le prefixe "self." permet de déclarer une méthode de classe
|
358
|
+
def self.create(nbRows, nbCols, value)
|
359
|
+
Matrix.rows(Array.new(nbRows, Array.new(nbCols, value)))
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
def left(a = '', b)
|
364
|
+
c = b - 1
|
365
|
+
a.to_s[0..c]
|
366
|
+
end
|
367
|
+
|
368
|
+
def chars(a, b, c = '')
|
369
|
+
c.to_s[a - 1..b - 1]
|
370
|
+
end
|
371
|
+
|
372
|
+
# visiblematrix.each_with_index do |x, xi|
|
373
|
+
# x.each_with_index do |y, yi|
|
374
|
+
# puts "element [#{xi}, #{yi}] is #{y}"
|
375
|
+
# end
|
376
|
+
# end
|
377
|
+
|
378
|
+
def offset(tofind = '', pack = '')
|
379
|
+
a = pack.ok.index(tofind)
|
380
|
+
if a.nil?
|
381
|
+
a = 0
|
382
|
+
else
|
383
|
+
a += 1
|
384
|
+
end
|
385
|
+
a
|
386
|
+
end
|
387
|
+
|
388
|
+
def length(a = '')
|
389
|
+
a.length
|
390
|
+
end
|
391
|
+
|
392
|
+
def icrash(imessage = '')
|
393
|
+
d 'CRASH****: ' << imessage
|
394
|
+
# break
|
395
|
+
end
|
396
|
+
|
397
|
+
def m(ifld = '', ipack = '', icrashnow = '')
|
398
|
+
return '' if ipack == ''
|
399
|
+
|
400
|
+
if ifld == ''
|
401
|
+
if icrashnow == true
|
402
|
+
icrash "mExtFrmPck:fldNotFound:'" << ifld << "'"
|
403
|
+
return '***CRASH'
|
404
|
+
else
|
405
|
+
return ''
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
a = ipack[ifld]
|
410
|
+
|
411
|
+
a = '' if a.nil?
|
412
|
+
|
413
|
+
a
|
414
|
+
end
|
415
|
+
|
416
|
+
# def m(ifld='', ipack='', icrashnow='')
|
417
|
+
# r = "\n".ok
|
418
|
+
# mchar = 245.chr.ok.to_s
|
419
|
+
# rrr = mchar << ifld << ","
|
420
|
+
# get offset(rrr, ipack)
|
421
|
+
# if @it == 0 # multiline pck
|
422
|
+
# rrr = mchar << ifld << r
|
423
|
+
# get offset(rrr, ipack)
|
424
|
+
# ifldend = mchar << "end" << ifld
|
425
|
+
# iendc = offset(ifldend, ipack) - 2
|
426
|
+
# if iendc == 0 or iendc <= @it
|
427
|
+
# if icrashnow == true
|
428
|
+
# icrash "mExtFrmPck:fldNotFound:'" << ifld << "'"
|
429
|
+
# return "***CRASH"
|
430
|
+
# end
|
431
|
+
# if ipack == ''
|
432
|
+
# get m(ifld, fiivar(), true)
|
433
|
+
# else
|
434
|
+
# get m(ifld, mreformat(ipack), true)
|
435
|
+
# end
|
436
|
+
# else
|
437
|
+
# istart = @it + (ifld.length) + 2
|
438
|
+
# get ipack.char(istart, iendc)
|
439
|
+
# end
|
440
|
+
# else
|
441
|
+
# ifldend = r
|
442
|
+
# istart = @it + length(ifld) + 2
|
443
|
+
# ilen = length(ipack)
|
444
|
+
# rrr = ipack.char(istart, ilen) << r
|
445
|
+
# iendc = offset(ifldend, rrr) - 2 + istart
|
446
|
+
# get ipack.char(istart, iendc)
|
447
|
+
# end
|
448
|
+
# return @it
|
449
|
+
# end
|
450
|
+
|
451
|
+
# def mreformat(ipack='')
|
452
|
+
# r = "\n".ok
|
453
|
+
# aa = ''
|
454
|
+
# mchar = 245.chr.to_s.ok
|
455
|
+
# mend = 178.chr.to_s.ok
|
456
|
+
# return '' if ipack == ''
|
457
|
+
# until 1 == 2 do
|
458
|
+
# break if ipack.number_of_lines == 0
|
459
|
+
# get ipack.ok.line(1)
|
460
|
+
# ipack = ipack.ok.delete_lines(1)
|
461
|
+
|
462
|
+
# if @it.char(1) == mchar
|
463
|
+
# aa = aa << it << r
|
464
|
+
|
465
|
+
# next if @it.contains(",")
|
466
|
+
|
467
|
+
# @it = @it.delete_char(1)
|
468
|
+
# rrr = mchar.ok << "end".ok << @it.ok
|
469
|
+
# iend = offset(rrr, ipack.ok)
|
470
|
+
# icrash "reformat:StartedButNoEnd" if iend == 0
|
471
|
+
# aa = aa.ok << ipack.char(1, iend)
|
472
|
+
# ipack = ipack.delete_char(1, iend)
|
473
|
+
# aa = aa << ipack.line(1) << r
|
474
|
+
# ipack = ipack.delete_lines(1)
|
475
|
+
|
476
|
+
# next
|
477
|
+
# else
|
478
|
+
# aa = aa << mchar << it << r
|
479
|
+
# end
|
480
|
+
# end
|
481
|
+
|
482
|
+
# aa = aa << mend
|
483
|
+
# return aa.to_s
|
484
|
+
# end
|
485
|
+
|
486
|
+
def ireplaceachar(aa)
|
487
|
+
a = aa[0]
|
488
|
+
b = aa[1]
|
489
|
+
aa = aa.delete_char(1, 2)
|
490
|
+
aa = aa.gsub(a, b)
|
491
|
+
aa
|
492
|
+
end
|
493
|
+
|
494
|
+
def ms(ipart = '', inewvalue = '', ipack = '')
|
495
|
+
ipack = {} if ipack == '' || ipack.nil?
|
496
|
+
return ipack if ipart == ''
|
497
|
+
|
498
|
+
b = {}
|
499
|
+
b[ipart] = inewvalue
|
500
|
+
ipack.update(b)
|
501
|
+
end
|
502
|
+
|
503
|
+
def md(ipack)
|
504
|
+
ipack.keys.join("\n")
|
505
|
+
end
|
506
|
+
|
507
|
+
# need to check strange symbols on a Mac, since Window mixes up chars
|
508
|
+
# def ms(ipart='', inewvalue='', ipack='')
|
509
|
+
|
510
|
+
# def clean
|
511
|
+
# a = self
|
512
|
+
# mend = 178.chr.to_s.ok
|
513
|
+
# mOther = 237.chr.to_s.ok
|
514
|
+
# if a.contains(mend) then
|
515
|
+
# rrr = mend << mOther << a
|
516
|
+
# a = ireplaceachar(rrr)
|
517
|
+
# end
|
518
|
+
# a
|
519
|
+
# end
|
520
|
+
|
521
|
+
# r = "\n".to_s.ok
|
522
|
+
# rrr = ''.to_s.ok
|
523
|
+
# mchar = 245.chr.to_s.ok
|
524
|
+
# mend = 178.chr.to_s.ok
|
525
|
+
|
526
|
+
# icrash "ms():part not defined" if ipart == ''
|
527
|
+
# ipack = mreformat(ipack) if ipack.lastchar != mend and ipack != ''
|
528
|
+
# ipart = ipart.clean
|
529
|
+
# inewvalue = inewvalue.clean
|
530
|
+
|
531
|
+
# if inewvalue.number_of_lines < 2
|
532
|
+
# inewpart = mchar << ipart << ',' << inewvalue
|
533
|
+
# else
|
534
|
+
# inewpart = mchar << ipart << r << inewvalue << r << "end" << ipart
|
535
|
+
# end
|
536
|
+
|
537
|
+
# rrr = r << mchar << ipart << ','
|
538
|
+
# rr2 = r << ipack
|
539
|
+
# get offset(rrr, rr2)
|
540
|
+
# if @it == 0
|
541
|
+
# rrr = r << mchar << ipart << r
|
542
|
+
# get offset(rrr, r << ipack) if @it == 0
|
543
|
+
# end
|
544
|
+
|
545
|
+
# if @it == 0
|
546
|
+
# if ipack == ''
|
547
|
+
# return inewpart << r << mend
|
548
|
+
# else
|
549
|
+
# ipack[-1] = inewpart << r << mend
|
550
|
+
# return ipack
|
551
|
+
# end
|
552
|
+
# end
|
553
|
+
# istartchar = it
|
554
|
+
|
555
|
+
# d "rrr: " << rrr.to_s.ok
|
556
|
+
# d "ipart: " << ipart.to_s.ok
|
557
|
+
# d "r: " << r.to_s.ok
|
558
|
+
|
559
|
+
# rrr = "end".ok << ipart.ok << r.ok
|
560
|
+
# iendoffset = offset(rrr.ok, ipack.ok << r.ok)
|
561
|
+
# ilastchar = iendoffset + length(ipart) + 3
|
562
|
+
# if iendoffset == 0
|
563
|
+
# yyy = ipack.ok << r.ok
|
564
|
+
# ilastChar = offset(r, yyy.char(istartchar, (length(ipack.ok)+1))) - 2 + istartchar
|
565
|
+
# end
|
566
|
+
# ipack[istartchar-1..ilastchar-1].ok = inewpart
|
567
|
+
# return ipack.ok
|
568
|
+
# end
|
569
|
+
|
570
|
+
def fiivar(aa = nil)
|
571
|
+
@iivar = '' if @iivar.nil?
|
572
|
+
@iivar = aa unless aa.nil?
|
573
|
+
@iivar
|
574
|
+
end
|
575
|
+
|
576
|
+
def t
|
577
|
+
a = ''
|
578
|
+
a = ms('first', 'a', a)
|
579
|
+
a = ms('second', 'b', a)
|
580
|
+
|
581
|
+
m('second', a)
|
582
|
+
end
|
data/test/test_zaphire.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaphire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.36
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lima90001
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: A library to make Ruby nicer to HyperCard users and Myself
|
13
|
+
description: A library to make Ruby nicer to HyperCard users and Myself and ++
|
14
14
|
email: lima90001@gmail.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
@@ -28,17 +28,17 @@ require_paths:
|
|
28
28
|
- lib
|
29
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
35
|
requirements:
|
36
|
-
- -
|
36
|
+
- - '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
39
|
requirements: []
|
40
40
|
rubyforge_project:
|
41
|
-
rubygems_version: 2.
|
41
|
+
rubygems_version: 2.0.14
|
42
42
|
signing_key:
|
43
43
|
specification_version: 3
|
44
44
|
summary: Zaphire!
|