meer 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/meer/cli.rb +29 -19
  3. data/lib/meer/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74a7b94baf63c2ed8889a76af69ad39639806cd5
4
- data.tar.gz: 153b800d8157f3c1791b6bef700179cbcee96430
3
+ metadata.gz: 995a0b2cdac02dc4d8d2b23f391252953ef1b1ae
4
+ data.tar.gz: b30fe6ee33e7dbeb8f942b9f43135e41dbc08348
5
5
  SHA512:
6
- metadata.gz: ca38c0d7262817d04f2ee2e3e212a9d8abfe8ca5aba6b388ef832b74719a36ad56927b872e5f3c05cb9bd340060fca43d9441efb384c7820cc6631a9dd3324a1
7
- data.tar.gz: 84f87d38740de815c5e25e5db9f24883a68835d6b7d78ee0102d3822b83b06bc3d88c446d78e320beccf561ef37475022a22e42be52750de45f07c2e0b85933b
6
+ metadata.gz: 9696472be4953387cf8a990f998ddaa66d8075a16bf2c7d24469fb2f96485af96369b055572b57ee2ea5b902dc35f89f895faecbdd3911ad18046fbcaa4bb9c9
7
+ data.tar.gz: ea0b4bf9610f3acda7e213e0b143f791927ae160cd6e31b91880c7aa8c9d8a4f2f2e605f596ed8f074ce89f7354be062fe8f004b69c5c4d27153a63eede2507a
data/lib/meer/cli.rb CHANGED
@@ -38,8 +38,10 @@ module Meer
38
38
  data = client.workbook_data(workbook, sheet)
39
39
  rows = CSV.parse(data, :headers => true).to_a
40
40
  headers = rows.slice!(0)
41
- filter!(headers, rows, options[:filter]) if options[:filter]
42
- sort!(headers, rows, options[:sort]) if options[:sort]
41
+ schema = parse_schema(headers, rows.first)
42
+
43
+ filter!(schema, rows, options[:filter]) if options[:filter]
44
+ sort!(schema, rows, options[:sort]) if options[:sort]
43
45
 
44
46
  puts Terminal::Table.new(headings: headers, rows: rows)
45
47
  end
@@ -51,38 +53,46 @@ module Meer
51
53
  @client = Datameer.new ENV['DATAMEER_URL'], user, password
52
54
  end
53
55
 
54
- def filter! headers, rows, filter_str
55
- cols = filter_str.split(',').map do |name|
56
+ def parse_schema(headers, row)
57
+ schema = Hash.new
58
+ headers.each_with_index do |col_name, idx|
59
+
60
+ type = :number if Float(row[idx]) rescue false
61
+ type ||= :time if row[idx] =~ /\A\w+ \d{1,2}, \d{4} \d{1,2}:\d{1,2}:\d{1,2} (AM|PM)\z/
62
+ type ||= :string
63
+
64
+ schema[col_name] = OpenStruct.new type: type, index: idx
65
+ end
66
+
67
+ schema
68
+ end
69
+
70
+ def filter! schema, rows, filter_str
71
+ cols = filter_str.split(?,).map do |name|
56
72
  name, q = name.split('=')
57
- col = headers.find_index(name)
58
- OpenStruct.new(col: col, query: q)
73
+ OpenStruct.new(col: schema[name], query: q)
59
74
  end
60
75
 
61
76
  rows.select! do |row|
62
- cols.map{|c| row[c.col].to_s == c.query}.all?
77
+ cols.map{|c| row[c.col.index].to_s =~ /#{c.query}/ }.all?
63
78
  end
64
79
  end
65
80
 
66
81
 
67
- def sort! headers, rows, sort_str
82
+ def sort! schema, rows, sort_str
68
83
  cols = sort_str.split(',').map do |name|
69
84
  reverse = name[-1] == '-'
70
85
  name = name[0..-2] if reverse
71
- col = headers.find_index(name)
72
-
73
- type = :number if Float(rows.first[col]) rescue false
74
- type = :time if rows.first[col] =~ /\A\w+ \d{1,2}, \d{4} \d{1,2}:\d{1,2}:\d{1,2} (AM|PM)\z/
75
- type ||= :string
76
86
 
77
- OpenStruct.new(col: col, type: type, reverse: reverse)
87
+ OpenStruct.new(col: schema[name], reverse: reverse)
78
88
  end
79
89
 
80
90
  rows.sort_by! do |row|
81
- cols.map do |i|
82
- val = row[i.col]
83
- val = val.to_f if i.type == :number
84
- val = Time.parse(val) if i.type == :time
85
- val = ReverseOrder.new(val) if i.reverse
91
+ cols.map do |c|
92
+ val = row[c.col.index]
93
+ val = val.to_f if c.col.type == :number
94
+ val = Time.parse(val) if c.col.type == :time
95
+ val = ReverseOrder.new(val) if c.reverse
86
96
  val
87
97
  end
88
98
  end
data/lib/meer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Meer
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - philip.monroe