meer 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/meer/cli.rb +29 -19
- data/lib/meer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 995a0b2cdac02dc4d8d2b23f391252953ef1b1ae
|
4
|
+
data.tar.gz: b30fe6ee33e7dbeb8f942b9f43135e41dbc08348
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
42
|
-
|
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
|
55
|
-
|
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
|
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
|
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!
|
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:
|
87
|
+
OpenStruct.new(col: schema[name], reverse: reverse)
|
78
88
|
end
|
79
89
|
|
80
90
|
rows.sort_by! do |row|
|
81
|
-
cols.map do |
|
82
|
-
val = row[
|
83
|
-
val = val.to_f if
|
84
|
-
val = Time.parse(val) if
|
85
|
-
val = ReverseOrder.new(val) if
|
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