meer 0.0.4 → 0.0.5

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 +45 -2
  3. data/lib/meer/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb5bbaf30530129f3d6a93e16ba7192b79d5b71c
4
- data.tar.gz: 2bf93b8264bd66b9a3f4863aa598983efb5caf60
3
+ metadata.gz: 2e62dab0fd5d4a9a6a34e93968661a539d69fc8c
4
+ data.tar.gz: 55650f992f5e311db2e99c6a52e361c05f59039c
5
5
  SHA512:
6
- metadata.gz: b923dcc36800a39ad43aada5093ded18595623d35d7712e5ef6c238698f16ae8bb5f3fd2c3969cebe40ac3685b5d746327ca820e728496c2d51a6a8b8c3e25b8
7
- data.tar.gz: e60506b12cfde9257ceaf34304012f2f409214f20d9ca9f7c1c89078d19b1a8193f18dc3882db014138581e7b0e932638e4b0eb13ac26d769b326c1bd9856106
6
+ metadata.gz: b736bc3ff843a59fb4f365a012838a93056ea58d7dbdf92501a7a9a555657d3ab4fc999a6af97a79218397ff0772c32b6e0bb7e427653e674a34e68646144dc2
7
+ data.tar.gz: e90df007ba9f46adedf3bd090fa7cd86a549b95bd7e263d3d8444dfab280900b2677c63d72348f5af0d034437ab8a7e6c34389d911e5d3a3651a2db8ab5d540d
data/lib/meer/cli.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'meer/datameer'
2
+ require 'time'
2
3
 
3
4
  module Meer
4
5
  class CLI < ::Thor
@@ -31,10 +32,14 @@ module Meer
31
32
  end
32
33
 
33
34
  desc "table [WORKBOOK-ID] [SHEET_NAME]", "Outputs a nicely formatted table for a given workbook"
35
+ option :sort, type: :string
34
36
  def table(workbook, sheet)
35
37
  data = client.workbook_data(workbook, sheet)
36
38
  rows = CSV.parse(data, :headers => true).to_a
37
- puts Terminal::Table.new headings: rows[0], rows: rows[1..-1]
39
+ headers = rows.slice!(0)
40
+ sort!(headers, rows, options[:sort]) if options[:sort]
41
+
42
+ puts Terminal::Table.new(headings: headers, rows: rows)
38
43
  end
39
44
 
40
45
 
@@ -43,5 +48,43 @@ module Meer
43
48
  def client user=nil, password=nil
44
49
  @client = Datameer.new ENV['DATAMEER_URL'], user, password
45
50
  end
51
+
52
+ def sort! headers, rows, sort_str
53
+ cols = sort_str.split(',').map do |name|
54
+ reverse = name[-1] == '-'
55
+ name = name[0..-2] if reverse
56
+ col = headers.find_index(name)
57
+
58
+ type = :number if Float(rows.first[col]) rescue false
59
+ 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/
60
+ type ||= :string
61
+
62
+ OpenStruct.new(col: col, type: type, reverse: reverse)
63
+ end
64
+
65
+ rows.sort_by! do |row|
66
+ cols.map do |i|
67
+ val = row[i.col]
68
+ val = val.to_f if i.type == :number
69
+ val = Time.parse(val) if i.type == :time
70
+ val = ReverseOrder.new(val) if i.reverse
71
+ val
72
+ end
73
+ end
74
+ end
75
+
76
+
77
+
78
+ class ReverseOrder
79
+ attr_reader :obj
80
+ def initialize obj
81
+ @obj = obj
82
+ end
83
+
84
+ def <=>(other)
85
+ -(@obj <=> other.obj)
86
+ end
87
+ end
46
88
  end
47
- end
89
+ end
90
+
data/lib/meer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Meer
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - philip.monroe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2015-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: highline