scout-gear 10.3.0 → 10.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.vimproject +0 -1
- data/VERSION +1 -1
- data/lib/scout/tsv/attach.rb +9 -1
- data/lib/scout/tsv/change_id.rb +3 -3
- data/lib/scout/tsv/index.rb +2 -2
- data/lib/scout/tsv/parser.rb +5 -3
- data/lib/scout/tsv/persist.rb +2 -2
- data/lib/scout/tsv/transformer.rb +21 -0
- data/lib/scout/tsv/util/process.rb +1 -1
- data/lib/scout/tsv.rb +53 -5
- data/lib/scout/workflow/definition.rb +8 -1
- data/scout-gear.gemspec +4 -4
- data/test/scout/test_tsv.rb +30 -0
- data/test/scout/tsv/persist/test_tkrzw.rb +90 -84
- data/test/scout/tsv/test_transformer.rb +12 -0
- data/test/scout/tsv/util/test_process.rb +20 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e4dbf9f73608dbc264f7f7584af04ac87bbeb2175b04a7ef50d2ef72cea8592
|
4
|
+
data.tar.gz: d423876c0f4cd1132128c519e9576afa7933f5c2f50b2f3498009a7dcba8ea30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d53af5f2c84362e664ff33f0afafafd5bb92756e5843c68466b81b09b51830a03a99093c18103a3f6a7d26a70099a283fc4841c346b223691b9afd6774399ac
|
7
|
+
data.tar.gz: 3c3fbc75f0ad79395211eb198198aa5e6e31de6e00a5d54375cfff5197d5cacfb6e0755889d157e4671b43edbbb1535b020814881df83a34227d231c623b0461
|
data/.vimproject
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
10.
|
1
|
+
10.4.0
|
data/lib/scout/tsv/attach.rb
CHANGED
@@ -40,12 +40,18 @@ module TSV
|
|
40
40
|
|
41
41
|
def self.attach(source, other, target: nil, fields: nil, match_key: nil, other_key: nil, one2one: true, complete: false, insitu: nil, persist_input: false, bar: nil)
|
42
42
|
source = TSV::Transformer.new source unless TSV === source || TSV::Parser === source
|
43
|
-
other = TSV.
|
43
|
+
other = TSV::Parser.new other unless TSV === other || TSV::Parser === other
|
44
44
|
|
45
45
|
fields = [fields] if String === fields
|
46
46
|
|
47
47
|
match_key, other_key = TSV.match_keys(source, other, match_key: match_key, other_key: other_key)
|
48
48
|
|
49
|
+
if ! (TSV === other)
|
50
|
+
other_key_name = other_key == :key ? other.key_field : other.fields[other_key]
|
51
|
+
other = TSV.open other, key_field: other_key_name, fields: fields, one2one: true, persist: persist_input
|
52
|
+
other_key = :key if other.key_field == source.key_field
|
53
|
+
end
|
54
|
+
|
49
55
|
if TSV::Transformer === source
|
50
56
|
source.dumper = case target
|
51
57
|
when :stream
|
@@ -117,6 +123,7 @@ module TSV
|
|
117
123
|
current_values[overlap] = v if current_values[overlap].nil? || String === current_values[overlap] && current_values[overlap].empty?
|
118
124
|
else
|
119
125
|
current_values[overlap] ||= []
|
126
|
+
next if v.nil?
|
120
127
|
current_values[overlap].concat (v - current_values[overlap])
|
121
128
|
end
|
122
129
|
end
|
@@ -154,6 +161,7 @@ module TSV
|
|
154
161
|
end
|
155
162
|
|
156
163
|
other_values.zip(overlaps).each do |v,overlap|
|
164
|
+
next if v.nil?
|
157
165
|
if false && overlap == :key
|
158
166
|
other_key = Array === v ? v : v.first
|
159
167
|
elsif source.type == :list
|
data/lib/scout/tsv/change_id.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module TSV
|
2
|
-
def self.change_key(source, new_key_field, identifiers: nil, one2one: false, stream: false, keep: false, persist_identifiers: nil)
|
2
|
+
def self.change_key(source, new_key_field, identifiers: nil, one2one: false, merge: true, stream: false, keep: false, persist_identifiers: nil)
|
3
3
|
source = TSV::Parser.new source if String === source
|
4
4
|
if identifiers && source.identify_field(new_key_field, strict: true).nil?
|
5
5
|
identifiers = identifiers.nil? ? source.identifiers : identifiers
|
6
6
|
new = source.attach(identifiers, fields: [new_key_field], insitu: false, one2one: true, persist_input: persist_identifiers)
|
7
|
-
new = new.change_key(new_key_field, keep: keep, stream: stream, one2one: one2one)
|
7
|
+
new = new.change_key(new_key_field, keep: keep, stream: stream, one2one: one2one, merge: merge)
|
8
8
|
return new
|
9
9
|
end
|
10
10
|
|
@@ -17,7 +17,7 @@ module TSV
|
|
17
17
|
[k, v]
|
18
18
|
end
|
19
19
|
|
20
|
-
stream ? transformer : transformer.tsv
|
20
|
+
stream ? transformer : transformer.tsv(merge: merge, one2one: one2one)
|
21
21
|
end
|
22
22
|
|
23
23
|
def change_key(*args, **kwargs)
|
data/lib/scout/tsv/index.rb
CHANGED
@@ -2,7 +2,7 @@ require_relative 'parser'
|
|
2
2
|
require_relative 'transformer'
|
3
3
|
require_relative 'persist/fix_width_table'
|
4
4
|
module TSV
|
5
|
-
def self.index(tsv_file, target:
|
5
|
+
def self.index(tsv_file, target: :key, fields: nil, order: true, bar: nil, **kwargs)
|
6
6
|
persist, type, persist_update, data_persist = IndiferentHash.process_options kwargs,
|
7
7
|
:persist, :persist_type, :persist_update, :data_persist,
|
8
8
|
:persist => false, :persist_type => "HDB"
|
@@ -10,7 +10,7 @@ module TSV
|
|
10
10
|
|
11
11
|
fields = :all if fields.nil?
|
12
12
|
|
13
|
-
Persist.persist(tsv_file, type, kwargs.merge(target: target, fields: fields, persist: persist, update: persist_update, :
|
13
|
+
Persist.persist(tsv_file, type, kwargs.merge(target: target, fields: fields, persist: persist, update: persist_update, prefix: "Index", other_options: {fields: fields, target: target, order: order})) do |filename|
|
14
14
|
if filename
|
15
15
|
index = ScoutCabinet.open(filename, true, type)
|
16
16
|
TSV.setup(index, :type => :single)
|
data/lib/scout/tsv/parser.rb
CHANGED
@@ -276,6 +276,7 @@ module TSV
|
|
276
276
|
end
|
277
277
|
@fix = fix
|
278
278
|
@options, @key_field, @fields, @first_line, @preamble = TSV.parse_header(@stream, fix:fix, header_hash:header_hash, sep:sep)
|
279
|
+
@options[:filename] = file if Path.is_filename?(file)
|
279
280
|
@options[:sep] = sep if @options[:sep].nil?
|
280
281
|
@options.merge!(:key_field => @key_field, :fields => @fields)
|
281
282
|
@type = @options[:type] || type
|
@@ -374,7 +375,7 @@ module TSV
|
|
374
375
|
end
|
375
376
|
|
376
377
|
def self.parse(stream, fix: true, header_hash: "#", sep: "\t", filename: nil, namespace: nil, unnamed: false, serializer: nil, **kwargs, &block)
|
377
|
-
parser = TSV::Parser.new
|
378
|
+
parser = TSV::Parser === stream ? stream : TSV::Parser.new(stream, fix: fix, header_hash: header_hash, sep: sep)
|
378
379
|
|
379
380
|
cast = kwargs[:cast]
|
380
381
|
cast = parser.options[:cast] if cast.nil?
|
@@ -407,8 +408,9 @@ module TSV
|
|
407
408
|
|
408
409
|
data = parser.traverse **kwargs, &block
|
409
410
|
data.type = type
|
410
|
-
data.filename = filename
|
411
|
-
data.namespace = namespace
|
411
|
+
data.filename = filename || parser.options[:filename]
|
412
|
+
data.namespace = namespace || parser.options[:namespace]
|
413
|
+
data.identifiers = parser.options[:identifiers]
|
412
414
|
data.unnamed = unnamed
|
413
415
|
data.save_extension_attr_hash if data.respond_to?(:save_extension_attr_hash)
|
414
416
|
data
|
data/lib/scout/tsv/persist.rb
CHANGED
@@ -3,12 +3,12 @@ require_relative 'persist/adapter'
|
|
3
3
|
|
4
4
|
begin
|
5
5
|
require_relative 'persist/tokyocabinet'
|
6
|
-
rescue
|
6
|
+
rescue Exception
|
7
7
|
end
|
8
8
|
|
9
9
|
begin
|
10
10
|
require_relative 'persist/tkrzw'
|
11
|
-
rescue
|
11
|
+
rescue Exception
|
12
12
|
end
|
13
13
|
|
14
14
|
Persist.save_drivers[:tsv] = proc do |file,content|
|
@@ -130,6 +130,27 @@ module TSV
|
|
130
130
|
res
|
131
131
|
end
|
132
132
|
|
133
|
+
def to_double
|
134
|
+
return self if self.type == :double
|
135
|
+
res = self.annotate({})
|
136
|
+
self.with_unnamed do
|
137
|
+
transformer = Transformer.new self, res
|
138
|
+
transformer.type = :double
|
139
|
+
transformer.traverse do |k,v|
|
140
|
+
case self.type
|
141
|
+
when :single
|
142
|
+
[k, [[v]]]
|
143
|
+
when :list
|
144
|
+
[k, v.collect{|v| [v] }]
|
145
|
+
when :flat
|
146
|
+
[k, [v]]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
res
|
151
|
+
end
|
152
|
+
|
153
|
+
|
133
154
|
def to_single
|
134
155
|
res = self.annotate({})
|
135
156
|
transformer = Transformer.new self, res
|
@@ -46,7 +46,7 @@ module TSV
|
|
46
46
|
def add_field(name = nil)
|
47
47
|
through do |key, values|
|
48
48
|
new_values = yield(key, values)
|
49
|
-
new_values = [new_values] if type == :double and not Array === new_values
|
49
|
+
new_values = [new_values].compact if type == :double and not Array === new_values
|
50
50
|
|
51
51
|
case
|
52
52
|
when (values.nil? and (fields.nil? or fields.empty?))
|
data/lib/scout/tsv.rb
CHANGED
@@ -28,9 +28,43 @@ module TSV
|
|
28
28
|
{:key_field => key, :fields => fields}.merge(rest_options)
|
29
29
|
end
|
30
30
|
|
31
|
+
class << self
|
32
|
+
alias original_setup setup
|
33
|
+
|
34
|
+
def setup(obj, *rest, &block)
|
35
|
+
|
36
|
+
if rest.length == 1 && String === rest.first
|
37
|
+
options = TSV.str2options(rest.first)
|
38
|
+
if Array === obj
|
39
|
+
default_value = case options[:type]
|
40
|
+
when :double, :flat, :list, nil
|
41
|
+
[]
|
42
|
+
when :single
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
obj = Misc.array2hash(obj, default_value)
|
46
|
+
end
|
47
|
+
original_setup(obj, options, &block)
|
48
|
+
else
|
49
|
+
if Array === obj
|
50
|
+
options = rest.first if Hash === rest.first
|
51
|
+
options ||= {}
|
52
|
+
default_value = case options[:type]
|
53
|
+
when :double, :flat, :list, nil
|
54
|
+
[]
|
55
|
+
when :single
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
obj = Misc.array2hash(obj, default_value)
|
59
|
+
end
|
60
|
+
original_setup(obj, *rest, &block)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
31
65
|
def self.str_setup(option_str, obj)
|
32
66
|
options = TSV.str2options(option_str)
|
33
|
-
setup(obj, options)
|
67
|
+
setup(obj, **options)
|
34
68
|
end
|
35
69
|
|
36
70
|
def self.open(file, options = {})
|
@@ -40,7 +74,17 @@ module TSV
|
|
40
74
|
persist_options = IndiferentHash.add_defaults persist_options, :prefix => "TSV", :type => :HDB
|
41
75
|
|
42
76
|
file = StringIO.new file if String === file && ! (Path === file) && file.index("\n")
|
43
|
-
|
77
|
+
|
78
|
+
source_name, other_options = case file
|
79
|
+
when StringIO
|
80
|
+
[file.inspect, options]
|
81
|
+
when TSV::Parser
|
82
|
+
[file.options[:filename], file.options]
|
83
|
+
else
|
84
|
+
[file, options]
|
85
|
+
end
|
86
|
+
|
87
|
+
Persist.persist(source_name, persist_options[:type], persist_options.merge(:other_options => other_options)) do |filename|
|
44
88
|
if filename
|
45
89
|
data = case persist_options[:type]
|
46
90
|
when :HDB, :BDB
|
@@ -52,7 +96,7 @@ module TSV
|
|
52
96
|
data = nil
|
53
97
|
end
|
54
98
|
options[:data] = data if data
|
55
|
-
options[:filename] = file
|
99
|
+
options[:filename] = TSV::Parser === file ? file.options[:filename] : file
|
56
100
|
|
57
101
|
if data
|
58
102
|
Log.debug "TSV open #{Log.fingerprint file} into #{Log.fingerprint data}"
|
@@ -60,8 +104,12 @@ module TSV
|
|
60
104
|
Log.debug "TSV open #{Log.fingerprint file}"
|
61
105
|
end
|
62
106
|
|
63
|
-
|
64
|
-
TSV.parse(
|
107
|
+
if TSV::Parser === file
|
108
|
+
TSV.parse(file, **options)
|
109
|
+
else
|
110
|
+
Open.open(file, grep: grep, invert_grep: invert_grep) do |f|
|
111
|
+
TSV.parse(f, **options)
|
112
|
+
end
|
65
113
|
end
|
66
114
|
end
|
67
115
|
end
|
@@ -103,7 +103,14 @@ module Workflow
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def task(name_and_type, &block)
|
106
|
-
|
106
|
+
case name_and_type
|
107
|
+
when Hash
|
108
|
+
name, type = name_and_type.collect.first
|
109
|
+
when Symbol
|
110
|
+
name, type = [name_and_type, :binary]
|
111
|
+
when String
|
112
|
+
name, type = [name_and_type, :binary]
|
113
|
+
end
|
107
114
|
type = type.to_sym if String === type
|
108
115
|
name = name.to_sym if String === name
|
109
116
|
@tasks ||= IndiferentHash.setup({})
|
data/scout-gear.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: scout-gear 10.
|
5
|
+
# stub: scout-gear 10.4.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "scout-gear".freeze
|
9
|
-
s.version = "10.
|
9
|
+
s.version = "10.4.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Miguel Vazquez".freeze]
|
14
|
-
s.date = "2023-08-
|
14
|
+
s.date = "2023-08-09"
|
15
15
|
s.description = "Temporary files, logs, path, resources, persistence, workflows, TSV, etc.".freeze
|
16
16
|
s.email = "mikisvaz@gmail.com".freeze
|
17
17
|
s.executables = ["scout".freeze]
|
@@ -167,7 +167,7 @@ Gem::Specification.new do |s|
|
|
167
167
|
]
|
168
168
|
s.homepage = "http://github.com/mikisvaz/scout-gear".freeze
|
169
169
|
s.licenses = ["MIT".freeze]
|
170
|
-
s.rubygems_version = "3.
|
170
|
+
s.rubygems_version = "3.5.0.dev".freeze
|
171
171
|
s.summary = "basic gear for scouts".freeze
|
172
172
|
|
173
173
|
s.specification_version = 4
|
data/test/scout/test_tsv.rb
CHANGED
@@ -310,6 +310,9 @@ row2 b bbb bbbb bb
|
|
310
310
|
|
311
311
|
tsv = TSV.str_setup("ID~ValueA,ValueB#:type=:flat", {})
|
312
312
|
assert_equal "ID", tsv.key_field
|
313
|
+
|
314
|
+
tsv = TSV.setup({}, "ID~ValueA,ValueB#:type=:flat")
|
315
|
+
assert_equal "ID", tsv.key_field
|
313
316
|
end
|
314
317
|
|
315
318
|
def test_cast_in_header
|
@@ -328,4 +331,31 @@ c 3
|
|
328
331
|
assert_include tsv.to_s, ":cast=:to_f"
|
329
332
|
end
|
330
333
|
end
|
334
|
+
|
335
|
+
def test_open_persist_parser
|
336
|
+
content =<<-'EOF'
|
337
|
+
#: :sep=/\s+/#:type=:double#:merge=:concat
|
338
|
+
#Id ValueA ValueB OtherID
|
339
|
+
row1 a|aa|aaa b Id1|Id2
|
340
|
+
row2 A B Id3
|
341
|
+
row2 a a id3
|
342
|
+
EOF
|
343
|
+
|
344
|
+
tsv = TmpFile.with_file(content) do |filename|
|
345
|
+
parser = TSV::Parser.new filename
|
346
|
+
tsv = TSV.open(parser, :persist => true)
|
347
|
+
tsv.close
|
348
|
+
Persist::CONNECTIONS.clear
|
349
|
+
TSV.open(filename, :persist => true)
|
350
|
+
end
|
351
|
+
|
352
|
+
assert_equal "Id", tsv.key_field
|
353
|
+
|
354
|
+
assert tsv.respond_to?(:persistence_class)
|
355
|
+
assert_equal TokyoCabinet::HDB, tsv.persistence_class
|
356
|
+
|
357
|
+
assert_include tsv.keys, 'row1'
|
358
|
+
assert_include tsv.keys, 'row2'
|
359
|
+
end
|
360
|
+
|
331
361
|
end
|
@@ -1,123 +1,129 @@
|
|
1
1
|
require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
|
2
|
-
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
3
2
|
|
4
3
|
require 'scout/tsv'
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
5
|
+
begin
|
6
|
+
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
|
7
|
+
class TestScoutTKRZW < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_open
|
12
|
+
TmpFile.with_file nil do |tmp|
|
13
|
+
db = ScoutTKRZW.open(tmp, true)
|
14
|
+
1000.times do |i|
|
15
|
+
db["foo#{i}"] = "bar#{i}"
|
16
|
+
end
|
17
|
+
assert_include db, 'foo1'
|
18
|
+
assert_equal 1000, db.keys.length
|
19
|
+
|
20
|
+
db.close
|
21
|
+
TmpFile.with_file nil do |tmp_alt|
|
22
|
+
Open.cp tmp, tmp_alt
|
23
|
+
db2 = ScoutTKRZW.open(tmp_alt, false)
|
24
|
+
assert_include db2, 'foo1'
|
25
|
+
assert_equal 1000, db2.keys.length
|
26
|
+
end
|
22
27
|
end
|
23
28
|
end
|
24
|
-
end
|
25
29
|
|
26
|
-
|
27
|
-
|
30
|
+
def test_tkrzw
|
31
|
+
content =<<-'EOF'
|
28
32
|
#: :sep=/\s+/#:type=:double#:merge=:concat
|
29
33
|
#Id ValueA ValueB OtherID
|
30
34
|
row1 a|aa|aaa b Id1|Id2
|
31
35
|
row2 A B Id3
|
32
36
|
row2 a a id3
|
33
|
-
|
37
|
+
EOF
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
39
|
+
tsv = TmpFile.with_file(content) do |filename|
|
40
|
+
Persist.persist(__method__, 'tkh') do
|
41
|
+
TSV.open(filename)
|
42
|
+
end
|
38
43
|
end
|
39
|
-
end
|
40
44
|
|
41
45
|
|
42
|
-
|
46
|
+
assert_equal %w(a aa aaa), tsv["row1"][0]
|
43
47
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
+
assert TSVAdapter === tsv
|
49
|
+
assert TSV === tsv
|
50
|
+
assert_include tsv.instance_variable_get(:@extension_attrs), :key_field
|
51
|
+
assert_include tsv.instance_variable_get(:@extension_attrs), :serializer
|
48
52
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
tsv.close
|
54
|
+
tsv_loaded = assert_nothing_raised do
|
55
|
+
TmpFile.with_file(content) do |filename|
|
56
|
+
Persist.persist(__method__, 'tkh') do
|
57
|
+
raise
|
58
|
+
end
|
54
59
|
end
|
55
60
|
end
|
61
|
+
|
62
|
+
assert_equal %w(a aa aaa), tsv_loaded["row1"][0]
|
56
63
|
end
|
57
64
|
|
58
|
-
|
59
|
-
|
65
|
+
def __test_benchmark1
|
66
|
+
TmpFile.with_file nil do |tmp|
|
67
|
+
|
68
|
+
Misc.benchmark(1000) do
|
69
|
+
db = ScoutTKRZW.open(tmp, true)
|
70
|
+
1000.times do |i|
|
71
|
+
db["foo#{i}"] = "bar#{i}"
|
72
|
+
end
|
73
|
+
10.times do
|
74
|
+
db.keys
|
75
|
+
end
|
76
|
+
10.times do |i|
|
77
|
+
db["foo#{i}"]
|
78
|
+
end
|
79
|
+
Open.rm tmp
|
80
|
+
end
|
81
|
+
|
82
|
+
Misc.benchmark(1000) do
|
83
|
+
db = ScoutCabinet.open(tmp, true)
|
84
|
+
1000.times do |i|
|
85
|
+
db["foo#{i}"] = "bar#{i}"
|
86
|
+
end
|
87
|
+
10.times do
|
88
|
+
db.keys
|
89
|
+
end
|
90
|
+
10.times do |i|
|
91
|
+
db["foo#{i}"]
|
92
|
+
end
|
93
|
+
db.close
|
94
|
+
Open.rm tmp
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
60
98
|
|
61
|
-
|
62
|
-
|
99
|
+
def test_benchmark2
|
100
|
+
TmpFile.with_file nil do |tmp|
|
63
101
|
|
64
|
-
Misc.benchmark(1000) do
|
65
102
|
db = ScoutTKRZW.open(tmp, true)
|
66
|
-
|
103
|
+
10000.times do |i|
|
67
104
|
db["foo#{i}"] = "bar#{i}"
|
68
105
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
106
|
+
|
107
|
+
Misc.benchmark(1000) do
|
108
|
+
100.times do |i|
|
109
|
+
db["foo#{i}"]
|
110
|
+
end
|
74
111
|
end
|
75
|
-
Open.rm tmp
|
76
|
-
end
|
77
112
|
|
78
|
-
|
113
|
+
Open.rm tmp
|
79
114
|
db = ScoutCabinet.open(tmp, true)
|
80
|
-
|
115
|
+
10000.times do |i|
|
81
116
|
db["foo#{i}"] = "bar#{i}"
|
82
117
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
db["foo#{i}"]
|
118
|
+
Misc.benchmark(1000) do
|
119
|
+
100.times do |i|
|
120
|
+
db["foo#{i}"]
|
121
|
+
end
|
88
122
|
end
|
89
|
-
db.close
|
90
|
-
Open.rm tmp
|
91
123
|
end
|
92
124
|
end
|
93
|
-
end
|
94
125
|
|
95
|
-
def test_benchmark2
|
96
|
-
TmpFile.with_file nil do |tmp|
|
97
|
-
|
98
|
-
db = ScoutTKRZW.open(tmp, true)
|
99
|
-
10000.times do |i|
|
100
|
-
db["foo#{i}"] = "bar#{i}"
|
101
|
-
end
|
102
|
-
|
103
|
-
Misc.benchmark(1000) do
|
104
|
-
100.times do |i|
|
105
|
-
db["foo#{i}"]
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
Open.rm tmp
|
110
|
-
db = ScoutCabinet.open(tmp, true)
|
111
|
-
10000.times do |i|
|
112
|
-
db["foo#{i}"] = "bar#{i}"
|
113
|
-
end
|
114
|
-
Misc.benchmark(1000) do
|
115
|
-
100.times do |i|
|
116
|
-
db["foo#{i}"]
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
126
|
end
|
121
|
-
|
127
|
+
rescue Exception
|
122
128
|
end
|
123
129
|
|
@@ -117,4 +117,16 @@ row2 A2|A22 B2|B22
|
|
117
117
|
tsv = TSV.open(content)
|
118
118
|
assert_equal %w(A1 A11 B1 B11), tsv.to_flat["row1"]
|
119
119
|
end
|
120
|
+
|
121
|
+
def test_to_double
|
122
|
+
content =<<-EOF
|
123
|
+
#: :sep=" "
|
124
|
+
#ID ValueA ValueB
|
125
|
+
row1 A1 B1
|
126
|
+
row2 A2 B2
|
127
|
+
EOF
|
128
|
+
|
129
|
+
tsv = TSV.open(content)
|
130
|
+
assert_equal %w(A1), tsv.to_double["row1"]["ValueA"]
|
131
|
+
end
|
120
132
|
end
|
@@ -43,5 +43,25 @@ row2 AA BB Id33
|
|
43
43
|
assert_equal %w(c cc ccc), tsv["row1"]["ValueC"]
|
44
44
|
assert_equal %w(C CC), tsv["row2"]["ValueC"]
|
45
45
|
end
|
46
|
+
|
47
|
+
def test_add_field_double_empty
|
48
|
+
content =<<-'EOF'
|
49
|
+
#: :sep=/\s+/#:type=:double
|
50
|
+
#Id ValueA ValueB OtherID
|
51
|
+
row1 a|aa|aaa b Id1|Id2
|
52
|
+
row2 A B Id3
|
53
|
+
row2 AA BB Id33
|
54
|
+
EOF
|
55
|
+
|
56
|
+
tsv = TmpFile.with_file(content) do |filename|
|
57
|
+
TSV.open(filename)
|
58
|
+
end
|
59
|
+
|
60
|
+
tsv.add_field "ValueC" do |k,v|
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_equal %w(), tsv["row1"]["ValueC"]
|
65
|
+
end
|
46
66
|
end
|
47
67
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout-gear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 10.
|
4
|
+
version: 10.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miguel Vazquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: scout-essentials
|
@@ -295,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
295
|
- !ruby/object:Gem::Version
|
296
296
|
version: '0'
|
297
297
|
requirements: []
|
298
|
-
rubygems_version: 3.
|
298
|
+
rubygems_version: 3.5.0.dev
|
299
299
|
signing_key:
|
300
300
|
specification_version: 4
|
301
301
|
summary: basic gear for scouts
|