mygegegems 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f952c5f24e2e7c759605e3b9bc916bd75a4c734f
4
- data.tar.gz: 3476a80a2482ab5ebffd4c2438a87c8ce58fa39e
3
+ metadata.gz: deda87a5957026286a659350a24c2bc19a38599e
4
+ data.tar.gz: 396693b54e065d040e45b39783723334a6707622
5
5
  SHA512:
6
- metadata.gz: 33be3563e85e799cde4ad9c76118daf23513f247e2bd5b8521305750d9d5be5ab3eff5c28382acfdf842a37726cf30a00d9d79c762851387e963150456fb1a47
7
- data.tar.gz: 9301ea6ba055e2917c6131332e91c819b8bf6b24e3a08a944e95ff171c11fb62e7ac63ce07e185098fe8deeddc03f97df2c028411326644bdcc3332610ac68e8
6
+ metadata.gz: 48d56fd754e23f7baeb419fc1006da98fa0c552d5f64fdd958786c0bbf031a598501cea08a8537f4c2228d99a9fe507441c1f682bb6da7c713e5f61739de67a3
7
+ data.tar.gz: 9e94366406bf857b57ec914a5f25c96dcf72d67ebd126ac0fb12eb9e7b23300fddabb96f1a708f7df7565bbc8decfab8514c40c75b491a72bfae43a84ffb2f31
@@ -24,6 +24,10 @@ module Mygegegems
24
24
  option :handle,
25
25
  aliases:'-h',
26
26
  desc:"Show stat of gems of a user with given handle"
27
+ option :sort,
28
+ aliases:'-s',
29
+ default:'download',
30
+ desc:"Sort a list by given title. any of 'name', 'diff' or 'download'"
27
31
  def stat
28
32
  if handle = options[:handle]
29
33
  gems = Mygegegems.gems(handle)
@@ -31,7 +35,7 @@ module Mygegegems
31
35
  border_line = "-" * 30
32
36
  total = gems.inject(0) { |sum, (_, dl)| sum + dl }
33
37
  num_of_gems = gems.size
34
- body = body(gems, {}, total.to_s.size, 3)
38
+ body = body(gems, {}, total.to_s.size, 3, options[:sort])
35
39
  footer = footer(total, nil, gems.size)
36
40
  else
37
41
  invoke(:update, [], {}) if options[:update]
@@ -43,7 +47,7 @@ module Mygegegems
43
47
  space1, space2 = [total, diff_total].map { |t| t.to_s.size }
44
48
  header = header(date, t_date, target)
45
49
  border_line = "-" * real_size(header)
46
- body = body(gems, diffs, space1, space2)
50
+ body = body(gems, diffs, space1, space2, options[:sort])
47
51
  footer = footer(total, diff_total, num_of_gems, space1, space2)
48
52
  end
49
53
 
@@ -54,21 +58,36 @@ module Mygegegems
54
58
  puts footer
55
59
  end
56
60
 
61
+ desc "version", "Show Mygegegems version"
62
+ def version
63
+ puts "Mygegegems #{Mygegegems::VERSION} (c) 2014 kyoendo"
64
+ end
65
+ map "-v" => :version
66
+
57
67
  no_tasks do
58
68
  def header(date1, date2, label)
59
69
  "As of #{date1} (#{label}: \e[33m#{date2}\e[0m)"
60
70
  end
61
71
 
62
- def body(gems, diffs, space1, space2)
63
- gems = gems.sort_by { |_, dl| -dl }
64
- gems.map do |name, dl|
65
- if diffs && (diff = diffs[name])
66
- "%#{space1}d \e[33m+%#{space2}d \e[32m%s\e[0m" % [dl, diffs[name], name]
67
- else
68
- none = "-".center(space2)
69
- "%#{space1}d \e[33m#{none} \e[32m%s\e[0m" % [dl, name]
70
- end
71
- end
72
+ def body(gems, diffs, space1, space2, sort)
73
+ gems.map { |name, dl|
74
+ diff = diffs && diffs[name] || -1
75
+ [dl, diff, name]
76
+ }.sort_by { |arr|
77
+ case sort.intern
78
+ when :download then -arr[0]
79
+ when :diff then -arr[1]
80
+ when :name then arr[2]
81
+ else -arr[0]
82
+ end
83
+ }.map { |dl, diff, name|
84
+ if diff >= 0
85
+ "%#{space1}d \e[33m+%#{space2}d \e[32m%s\e[0m" % [dl, diff, name]
86
+ else
87
+ none = "-".center(space2)
88
+ "%#{space1}d \e[33m#{none} \e[32m%s\e[0m" % [dl, name]
89
+ end
90
+ }
72
91
  end
73
92
 
74
93
  def footer(total, diff_total, num_of_gems, space1=0, space2=0)
@@ -1,3 +1,3 @@
1
1
  module Mygegegems
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -77,5 +77,39 @@ describe Mygegegems::CLI do
77
77
  end
78
78
  end
79
79
  end
80
+
81
+ context "with sort option" do
82
+ it "sorts results by name" do
83
+ described_class.start(['stat', '--sort', 'name'])
84
+ expect($stdout.string).to eq ~<<-EOS
85
+ As of 2014-07-11 (last: \e[33m2014-07-10\e[0m)
86
+ -----------------------------------
87
+ 762 \e[33m+ 2 \e[32memot\e[0m
88
+ 354 \e[33m+ 14 \e[32mgh-diff\e[0m
89
+ 3345 \e[33m+ 0 \e[32mlet_it_fall\e[0m
90
+ 299 \e[33m+ 18 \e[32mmatreska\e[0m
91
+ 297 \e[33m+ 30 \e[32mtildoc\e[0m
92
+ 2225 \e[33m+100 \e[32mtogglate\e[0m
93
+ -----------------------------------
94
+ 7282 \e[33m+164 \e[32m6 gems\e[0m
95
+ EOS
96
+ end
97
+
98
+ it "sorts results by diff" do
99
+ described_class.start(['stat', '--sort', 'diff'])
100
+ expect($stdout.string).to eq ~<<-EOS
101
+ As of 2014-07-11 (last: \e[33m2014-07-10\e[0m)
102
+ -----------------------------------
103
+ 2225 \e[33m+100 \e[32mtogglate\e[0m
104
+ 297 \e[33m+ 30 \e[32mtildoc\e[0m
105
+ 299 \e[33m+ 18 \e[32mmatreska\e[0m
106
+ 354 \e[33m+ 14 \e[32mgh-diff\e[0m
107
+ 762 \e[33m+ 2 \e[32memot\e[0m
108
+ 3345 \e[33m+ 0 \e[32mlet_it_fall\e[0m
109
+ -----------------------------------
110
+ 7282 \e[33m+164 \e[32m6 gems\e[0m
111
+ EOS
112
+ end
113
+ end
80
114
  end
81
115
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mygegegems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyoendo