favourite-language 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,6 +5,13 @@ This gem provides an command line tool for returning a user's favourite
5
5
  programming language. You can either return their favourite programming
6
6
  language by number of repositories or by repository size.
7
7
 
8
+ Installation
9
+ ------------
10
+
11
+ ``` sh
12
+ $ gem install favourite-language
13
+ ```
14
+
8
15
  Usage
9
16
  -----
10
17
 
@@ -1,61 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require "thor"
3
- require "octokit"
4
-
5
- Octokit.auto_paginate = true
6
-
7
- class FavouriteLanguage < Thor
8
- package_name "Favourite Language"
9
-
10
- desc "by_repo USER", "Get the favourite programming language by the number of repositories"
11
- def by_repo(user)
12
- message = "The favourite language of %s by number of repositories is %s"
13
- language = favorite_language(:by_num_repos, user)
14
- puts message % [user, language] if language
15
- end
16
-
17
- desc "by_size USER", "Get the favourite programming labguage by repository size"
18
- def by_size(user)
19
- message = "The favourite language of %s by repository size is %s"
20
- language = favorite_language(:by_size, user)
21
- puts message % [user, language] if language
22
- end
23
-
24
- private
25
-
26
- def favorite_language(method, user)
27
- begin
28
- send(:"languages_#{method}", user).max_by{ |l, n| n }.first
29
- rescue Octokit::NotFound
30
- puts "Sorry, #{user} doesn't exist"
31
- rescue Octokit::TooManyRequests
32
- puts "Sorry, your API limit has been reached"
33
- rescue Octokit::ClientError => e
34
- puts "Sorry, unexpected client error: {e.message}"
35
- rescue Octokit::ServerError => e
36
- puts "Sorry, unexpected server error: {e.message}"
37
- end
38
- end
39
-
40
- def languages_by_num_repos(user)
41
- repositories(user).inject({}) do |languages, repository|
42
- language = repository.language
43
- languages[language] = languages.fetch(language, 0) + 1
44
- languages
45
- end
46
- end
47
-
48
- def languages_by_size(user)
49
- repositories(user).inject({}) do |languages, repository|
50
- language = repository.language
51
- languages[language] = languages.fetch(language, 0) + repository.size
52
- languages
53
- end
54
- end
55
-
56
- def repositories(user)
57
- Octokit.repositories(user)
58
- end
59
- end
2
+ $: << File.expand_path("../../lib/", __FILE__)
3
+ require "favourite_language"
60
4
 
61
5
  FavouriteLanguage.start
@@ -1,16 +1,25 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = 'favourite-language'
3
- s.version = '0.1.0'
4
- s.author = 'Andrew White'
5
- s.email = 'andyw@pixeltrix.co.uk'
6
- s.summary = <<-EOS
2
+ s.name = 'favourite-language'
3
+ s.version = '0.1.1'
4
+ s.author = 'Andrew White'
5
+ s.email = 'andyw@pixeltrix.co.uk'
6
+ s.homepage = 'https://github.com/pixeltrix/favourite-language'
7
+ s.summary = <<-EOS
7
8
  Provides a command line tool for getting a user's favourite
8
9
  programming language from their GitHub public repositories.
9
10
  EOS
10
11
 
11
12
  s.add_dependency 'thor', '~> 0.18'
12
13
  s.add_dependency 'octokit', '~> 2.0'
14
+ s.add_development_dependency 'rspec', '~> 2.14'
15
+
16
+ s.files = [
17
+ 'bin/favourite-language',
18
+ 'lib/favourite_language.rb',
19
+ 'favourite-language.gemspec',
20
+ 'LICENSE.md',
21
+ 'README.md'
22
+ ]
13
23
 
14
- s.files = %w[bin/favourite-language favourite-language.gemspec LICENSE.md README.md]
15
24
  s.executables = %w[favourite-language]
16
25
  end
@@ -0,0 +1,56 @@
1
+ require "thor"
2
+ require "octokit"
3
+
4
+ Octokit.auto_paginate = true
5
+
6
+ class FavouriteLanguage < Thor
7
+ package_name "Favourite Language"
8
+
9
+ desc "by_repo USER", "Get the favourite programming language by the number of repositories"
10
+ def by_repo(user)
11
+ message = "The favourite language of %s by number of repositories is %s"
12
+ language = favorite_language(:by_num_repos, user)
13
+ puts message % [user, language] if language
14
+ end
15
+
16
+ desc "by_size USER", "Get the favourite programming labguage by repository size"
17
+ def by_size(user)
18
+ message = "The favourite language of %s by repository size is %s"
19
+ language = favorite_language(:by_size, user)
20
+ puts message % [user, language] if language
21
+ end
22
+
23
+ private
24
+
25
+ def favorite_language(method, user)
26
+ begin
27
+ send(:"languages_#{method}", user).max_by{ |l, n| n }.first
28
+ rescue Octokit::NotFound
29
+ puts "Sorry, #{user} doesn't exist"
30
+ rescue Octokit::TooManyRequests
31
+ puts "Sorry, your API limit has been reached"
32
+ rescue Octokit::ClientError => e
33
+ puts "Sorry, unexpected client error: #{e.message}"
34
+ rescue Octokit::ServerError => e
35
+ puts "Sorry, unexpected server error: #{e.message}"
36
+ end
37
+ end
38
+
39
+ def languages_by_num_repos(user)
40
+ repositories(user).inject(Hash.new(0)) do |languages, repository|
41
+ languages[repository.language] += 1
42
+ languages
43
+ end
44
+ end
45
+
46
+ def languages_by_size(user)
47
+ repositories(user).inject(Hash.new(0)) do |languages, repository|
48
+ languages[repository.language] += repository.size
49
+ languages
50
+ end
51
+ end
52
+
53
+ def repositories(user)
54
+ Octokit.repositories(user)
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: favourite-language
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.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: 2013-10-04 00:00:00.000000000 Z
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '2.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.14'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
46
62
  description:
47
63
  email: andyw@pixeltrix.co.uk
48
64
  executables:
@@ -51,10 +67,11 @@ extensions: []
51
67
  extra_rdoc_files: []
52
68
  files:
53
69
  - bin/favourite-language
70
+ - lib/favourite_language.rb
54
71
  - favourite-language.gemspec
55
72
  - LICENSE.md
56
73
  - README.md
57
- homepage:
74
+ homepage: https://github.com/pixeltrix/favourite-language
58
75
  licenses: []
59
76
  post_install_message:
60
77
  rdoc_options: []