Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Split classes into separate files

  • Loading branch information...
commit cdc36753f2695e1e6bad4182cbd2746e86edb455 1 parent d13f233
@adarsh adarsh authored
Showing with 100 additions and 96 deletions.
  1. +6 −96 gitsucker.rb
  2. +60 −0 lib/author.rb
  3. +34 −0 lib/repo.rb
View
102 gitsucker.rb
@@ -1,103 +1,13 @@
#!/usr/bin/env ruby
+require './lib/author'
+require './lib/repo'
require 'open-uri'
-require 'nokogiri'
require 'json'
-class Repo
- attr_accessor :forking_authors
-
- def initialize(name)
- @name = name
- end
-
- def get_forking_authors
- fork_authors.
- map { |name| Author.new(name) }.
- sort_by { |author| author.score }.
- reverse
- end
-
- private
-
- def author
- JSON.parse(open(search_url).read)['repositories'].first['username']
- end
-
- def author_url
- 'https://api.github.com/repos/' + author + '/' + @name + '/forks'
- end
-
- def fork_authors
- JSON.parse(open(author_url).read).map { |fork| fork['owner']['login'] }
- end
-
- def search_url
- 'https://api.github.com/legacy/repos/search/' + @name
- end
-end
-
-class Author
- attr_reader :score
-
- ORIGINAL_REPO_VALUE = 3
- RUBY_REPO_VALUE = 2
- JS_REPO_VALUE = 2
- FORKED_REPO_VALUE = 1
-
- def initialize(name)
- @name = name
- @score = user_score
- end
-
- def stats
- [
- @name,
- public_repo_count,
- original_repo_count,
- forked_repo_count,
- ruby_repo_count,
- js_repo_count,
- @score
- ]
- end
-
- def self.stat_types
- %w(name all originals forked ruby js score)
- end
-
- private
-
- def forked_repo_count
- @forked ||= public_repo_count - original_repo_count
- end
-
- def github_profile
- @github_profile ||= Nokogiri::HTML(open('https://github.com/' + @name))
- end
-
- def js_repo_count
- @js ||= github_profile.css('ul.repo-stats').select{|li| li.text =~ /JavaScript/}.count
- end
-
- def original_repo_count
- @original ||= github_profile.css('.source').count
- end
-
- def public_repo_count
- @public_count ||= github_profile.css('.public').count
- end
-
- def ruby_repo_count
- @ruby ||= github_profile.css('ul.repo-stats').select{|li| li.text =~ /Ruby/}.count
- end
-
- def user_score
- score = original_repo_count * ORIGINAL_REPO_VALUE
- score += ruby_repo_count * RUBY_REPO_VALUE
- score += js_repo_count * JS_REPO_VALUE
- score += forked_repo_count * FORKED_REPO_VALUE
- end
-end
+ORIGINAL_REPO_VALUE = 3
+RUBY_REPO_VALUE = 2
+JS_REPO_VALUE = 2
+FORKED_REPO_VALUE = 1
ARGV.each do |input|
begin
View
60 lib/author.rb
@@ -0,0 +1,60 @@
+#!/usr/bin/env ruby
+require 'nokogiri'
+
+class Author
+ attr_reader :score
+
+ def initialize(name)
+ @name = name
+ @score = user_score
+ end
+
+ def stats
+ [
+ @name,
+ public_repo_count,
+ original_repo_count,
+ forked_repo_count,
+ ruby_repo_count,
+ js_repo_count,
+ @score
+ ]
+ end
+
+ def self.stat_types
+ %w(name all originals forked ruby js score)
+ end
+
+ private
+
+ def forked_repo_count
+ @forked ||= public_repo_count - original_repo_count
+ end
+
+ def github_profile
+ @github_profile ||= Nokogiri::HTML(open('https://github.com/' + @name))
+ end
+
+ def js_repo_count
+ @js ||= github_profile.css('ul.repo-stats').select{|li| li.text =~ /JavaScript/}.count
+ end
+
+ def original_repo_count
+ @original ||= github_profile.css('.source').count
+ end
+
+ def public_repo_count
+ @public_count ||= github_profile.css('.public').count
+ end
+
+ def ruby_repo_count
+ @ruby ||= github_profile.css('ul.repo-stats').select{|li| li.text =~ /Ruby/}.count
+ end
+
+ def user_score
+ score = original_repo_count * ORIGINAL_REPO_VALUE
+ score += ruby_repo_count * RUBY_REPO_VALUE
+ score += js_repo_count * JS_REPO_VALUE
+ score += forked_repo_count * FORKED_REPO_VALUE
+ end
+end
View
34 lib/repo.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+class Repo
+ attr_accessor :forking_authors
+
+ def initialize(name)
+ @name = name
+ end
+
+ def get_forking_authors
+ fork_authors.
+ map { |name| Author.new(name) }.
+ sort_by { |author| author.score }.
+ reverse
+ end
+
+ private
+
+ def author
+ JSON.parse(open(search_url).read)['repositories'].first['username']
+ end
+
+ def author_url
+ 'https://api.github.com/repos/' + author + '/' + @name + '/forks'
+ end
+
+ def fork_authors
+ JSON.parse(open(author_url).read).map { |fork| fork['owner']['login'] }
+ end
+
+ def search_url
+ 'https://api.github.com/legacy/repos/search/' + @name
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.