rg_stats 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,7 +4,6 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "json"
7
- gem "yaml"
8
7
 
9
8
  group :development do
10
9
  gem "rspec", '~> 2.9.0'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rg_stats (0.0.1)
4
+ rg_stats (1.0.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/bin/rg_stats CHANGED
@@ -26,7 +26,15 @@ if user_name.nil?
26
26
  end
27
27
 
28
28
  url = "https://rubygems.org/api/v1/owners/#{user_name}/gems.json"
29
- data_as_json = open(url)
29
+ begin
30
+ data_as_json = open(url)
31
+ rescue SocketError => e
32
+ puts "It seems connection is not available. (#{e.message})"
33
+ exit
34
+ rescue OpenURI::HTTPError => e
35
+ puts "User #{user_name} has not been found. (#{e.message})"
36
+ exit
37
+ end
30
38
  old_data = PersistDataBetweenSessions.load
31
39
  old_map = {}
32
40
  old_data.each do |old_gem_info|
@@ -35,13 +43,14 @@ end
35
43
 
36
44
  stat = Statistic.new
37
45
  stat.load data_as_json
46
+
38
47
  puts ""
39
- puts "*" * 90
40
- stat.gem_info.each do |gem_info|
48
+ puts "*" * (stat.max_gem_name_size + 30)
49
+ stat.gem_infos.each do |gem_info|
41
50
  broj_izmjena = gem_info[1] - (old_map[gem_info[0]].nil? ? 0 : old_map[gem_info[0]])
42
51
  diff_from_last_time = broj_izmjena == 0 ? "" : " (+\e[32m#{broj_izmjena}\e[0m)"
43
- puts "%-55s: %8d %8s" % [ gem_info[0] , gem_info[1], diff_from_last_time ]
52
+ puts "%-#{stat.max_gem_name_size + 1}s=> %6d %6s" % [ gem_info[0] , gem_info[1], diff_from_last_time ]
44
53
  end
45
- puts "*" * 90
46
- PersistDataBetweenSessions.save(stat.gem_info)
54
+ puts "*" * (stat.max_gem_name_size + 30)
55
+ PersistDataBetweenSessions.save(stat.gem_infos)
47
56
 
@@ -5,9 +5,13 @@ class Statistic
5
5
  @data = JSON.load data
6
6
  end
7
7
 
8
- def gem_info
8
+ def gem_infos
9
9
  @data.reduce([]) do |result, gem_info|
10
10
  result << [ gem_info['name'], gem_info['downloads']]
11
11
  end.sort! { |a,b| a[1] <=> b[1] }.reverse
12
12
  end
13
+
14
+ def max_gem_name_size
15
+ gem_infos.map { |info| info[0].size }.sort[-1]
16
+ end
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module RgStats
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -4,7 +4,12 @@ require 'rg_stats'
4
4
  describe Statistic do
5
5
  it 'should water my plants' do
6
6
  subject.load TEST_DATA
7
- subject.gem_info.should == [["guerrilla_patch", 485], ["cube", 409]]
7
+ subject.gem_infos.should == [["guerrilla_patch", 485], ["cube", 409]]
8
+ end
9
+
10
+ it 'should know size of longest named gem' do
11
+ subject.load TEST_DATA
12
+ subject.max_gem_name_size.should == 15
8
13
  end
9
14
  end
10
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rg_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-06 00:00:00.000000000Z
12
+ date: 2012-04-07 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Get download statistic of yours gems on RubyGems
15
15
  email: