rbbt-util 5.34.7 → 5.34.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec5860171e51e2e53a8383ae8ea1156b79c7f75194d384c5aa2c43efd759e129
4
- data.tar.gz: a6ab8a782b3169eae1e475a2029e8a4f0ac2d12f375475ec70de9d97f513f21a
3
+ metadata.gz: 57270d81ae9b5c8106f216ca39c6f3b7981e9fac5667fe5c3a89e4b42286bf8b
4
+ data.tar.gz: 841a63f9e5345fd8eb58db5878fb9556bb9d623fb2c78583a24688da8a518610
5
5
  SHA512:
6
- metadata.gz: 2fb6a8ac5abee267891f6bb0736b659f202019de75fa0ecef80e955838a54013eaeabb495c44daff45196a8706821b706bfae75b095ce3ca8b82e8351436d4ef
7
- data.tar.gz: ab24e4ab588e75f94adfcd9a02e178511bd4471edadef18c6c49537974353b8b4d83c61438d8fe638acbc26101556637a92d5da325ebc135736da44558971334
6
+ metadata.gz: 3b4331f6fbbf25af0bd1bce2288fc5a39d06de0259ed74a2538ad785b2d48c2851321567c355dbbb612d8a478b8e40b8b16fe96ad3e497f61d28480795db88ee
7
+ data.tar.gz: 96621efdacb39998c672120f27347d92535fa8772381f39ae14e8e437f1ad7fe7c5176e3a0d6bcb54c6f89915aa5e928364af61e94f970d3fe6f2ba27d938408
@@ -527,13 +527,21 @@ module TSV
527
527
  self.unnamed = old_unnamed
528
528
 
529
529
  when String === method
530
- with_unnamed do
531
- through :key, key do |key, values|
532
- values = [values] if type == :single
533
- new[key] = self[key] if invert ^ (values.flatten.select{|v| v == method}.length > 0)
530
+ if method =~ /^([<>]=?)(.*)/
531
+ with_unnamed do
532
+ through :key, key do |key, values|
533
+ value = Array === values ? values.flatten.first : values
534
+ new[key] = self[key] if value.to_f.send($1, $2.to_f)
535
+ end
536
+ end
537
+ else
538
+ with_unnamed do
539
+ through :key, key do |key, values|
540
+ values = [values] if type == :single
541
+ new[key] = self[key] if invert ^ (values.flatten.select{|v| v == method}.length > 0)
542
+ end
534
543
  end
535
544
  end
536
-
537
545
  when Numeric === method
538
546
  with_unnamed do
539
547
  through :key, key do |key, values|
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbbt-util'
4
+ require 'rbbt/util/simpleopt'
5
+
6
+ $0 = "rbbt #{$previous_commands*""} #{ File.basename(__FILE__) }" if $previous_commands
7
+
8
+ options = SOPT.setup <<EOF
9
+ Select entries in a tsv based on some criteria
10
+
11
+ $ rbbt tsv subset [options] file.tsv <key> <criteria>
12
+
13
+ Subsets entries from a TSV file from a given list. Works with Tokyocabinet HDB and BDB as well.
14
+
15
+ -tch--tokyocabinet File is a TC HDB
16
+ -tcb--tokyocabinet_bd File is a TC BDB
17
+ -hh--header_hash* Change the character used to mark the header line (defaults to #)
18
+ -s--subset* Subset of keys (Comma-separated or file)
19
+ -m--merge Merge TSV rows
20
+ -h--help Help
21
+ EOF
22
+
23
+ SOPT.usage if options[:help]
24
+
25
+ file, key, criteria = ARGV
26
+
27
+ key, criteria, file = [file, key, nil] if criteria.nil?
28
+
29
+ file = STDIN if file == '-' || file.nil?
30
+
31
+ raise ParameterException, "Please specify the tsv file as argument" if file.nil?
32
+
33
+ options[:fields] = options[:fields].split(/,\|/) if options[:fields]
34
+ options[:header_hash] = options["header_hash"]
35
+
36
+ case
37
+ when options[:tokyocabinet]
38
+ tsv = Persist.open_tokyocabinet(file, false)
39
+ puts tsv.summary
40
+ when options[:tokyocabinet_bd]
41
+ tsv = Persist.open_tokyocabinet(file, false, nil, TokyoCabinet::BDB)
42
+ puts tsv.summary
43
+ else
44
+ tsv = TSV.open(file, options)
45
+ end
46
+
47
+ criteria = criteria.to_regexp.to_regexp if criteria =~ /\/.*\/.*/
48
+ puts tsv.select(key => criteria)
@@ -28,7 +28,7 @@ end
28
28
 
29
29
  file = ARGV.shift
30
30
 
31
- file = STDIN if file == '-'
31
+ file = STDIN if file == '-' || file.nil?
32
32
 
33
33
  case
34
34
  when options[:tokyocabinet]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-util
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.34.7
4
+ version: 5.34.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
11
+ date: 2022-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -452,6 +452,7 @@ files:
452
452
  - share/rbbt_commands/tsv/query
453
453
  - share/rbbt_commands/tsv/read
454
454
  - share/rbbt_commands/tsv/read_excel
455
+ - share/rbbt_commands/tsv/select
455
456
  - share/rbbt_commands/tsv/slice
456
457
  - share/rbbt_commands/tsv/sort
457
458
  - share/rbbt_commands/tsv/subset