Permalink
Browse files

Splitting classes out into different files

  • Loading branch information...
1 parent cdc3675 commit 4e1ca631070369059a4b4c134deed24c016ecc60 @adarsh adarsh committed Apr 30, 2012
Showing with 35 additions and 18 deletions.
  1. +5 −15 gitsucker.rb
  2. +0 −1 lib/author.rb
  3. +0 −2 lib/repo.rb
  4. +30 −0 lib/table.rb
View
20 gitsucker.rb
@@ -1,26 +1,16 @@
#!/usr/bin/env ruby
-require './lib/author'
-require './lib/repo'
require 'open-uri'
require 'json'
+require './lib/author'
+require './lib/repo'
+require './lib/table'
ORIGINAL_REPO_VALUE = 3
RUBY_REPO_VALUE = 2
JS_REPO_VALUE = 2
FORKED_REPO_VALUE = 1
ARGV.each do |input|
- begin
- puts 'Fetching data...'
- puts '%-20s %-10s %-10s %-10s %-10s %-10s %-10s' % Author.stat_types
-
- print '='*80
- puts
-
- Repo.new(input).get_forking_authors.each do |author|
- puts '%-20s %-10s %-10s %-10s %-10s %-10s %-10s' % author.stats
- end
- rescue
- puts 'Repo not found.'
- end
+ table = Table.new(input)
+ table.output_results
end
View
1 lib/author.rb
@@ -1,4 +1,3 @@
-#!/usr/bin/env ruby
require 'nokogiri'
class Author
View
2 lib/repo.rb
@@ -1,5 +1,3 @@
-#!/usr/bin/env ruby
-
class Repo
attr_accessor :forking_authors
View
30 lib/table.rb
@@ -0,0 +1,30 @@
+class Table
+ def initialize(input)
+ @input = input
+ end
+
+ def output_results
+ display_header
+
+ begin
+ Repo.new(@input).get_forking_authors.each do |author|
+ puts column_spacing % author.stats
+ end
+ rescue
+ puts 'Repo not found.'
+ end
+ end
+
+ private
+
+ def column_spacing
+ '%-20s %-10s %-10s %-10s %-10s %-10s %-10s'
+ end
+
+ def display_header
+ puts column_spacing % Author.stat_types
+ print '='*80
+ puts
+ end
+end
+

0 comments on commit 4e1ca63

Please sign in to comment.