Class: Galileo
- Inherits:
-
Object
- Object
- Galileo
- Defined in:
- lib/galileo.rb,
lib/galileo/version.rb
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(query) ⇒ Galileo
constructor
A new instance of Galileo.
Constructor Details
#initialize(query) ⇒ Galileo
Returns a new instance of Galileo.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/galileo.rb', line 13 def initialize(query) repos = [] config = Netrc.read unless config["api.github.com"] puts "" # \n login = [(print 'GitHub Username: '), STDIN.gets.rstrip][1] password = [(print 'GitHub Password: '), STDIN.noecho(&:gets).rstrip][1] config["api.github.com"] = login, password config.save end Octokit.configure do |client| client.netrc = true client.auto_paginate = true end APICache.store = Moneta.new(:File, dir: Dir.tmpdir) repos = APICache.get("starred", fail: [], timeout: 20, cache: 3600) do repos = [] puts "" # \n puts "Searching the stars..." # GET Octokit.starred(Octokit.user.login).concat(Octokit.repos(Octokit.user.login)).each do |repo| repos << [ repo.name || '', repo.description || '', repo.language || '', repo.owner.login || '', repo.stargazers_count || '', repo.updated_at || '' ] end repos.uniq end if repos.any? if query.any? languages = [] # If the language parameter if present if query.index('-l') languages = query.delete(query[query.index('-l') + 1]).split(',') query.delete('-l') end # Filter by the query repos.select! do |repo| # Join the arguments into a query q = query.join(' ').downcase repo[0].downcase.include?(q) or repo[1].downcase.include?(q) end # Sort by stars repos.sort_by! { |repo| -repo[4] } if query and repos.any? # If languages if languages.any? languages.map!(&:downcase) repos.select! do |repo| languages.include? repo[2].downcase end end end if repos.any? # Formatting repos.map! do |repo| repo[0] = repo[0].yellow # Language color-coating case repo[2] when 'Clojur' then repo[2] = repo[2].colorize(:light_red) when 'Ruby' then repo[2] = repo[2].red when 'CSS', 'CoffeeScript', 'Python' then repo[2] = repo[2].blue when 'Perl', 'Shell', 'Objective-C' then repo[2] = repo[2].colorize(:light_blue) when 'PHP', 'C#' then repo[2] = repo[2].magenta when 'Emacs Lisp', 'C++' then repo[2] = repo[2].colorize(:light_magenta) when 'Smalltalk', 'TeX' then repo[2] = repo[2].green when 'VimL', 'Scala' then repo[2] = repo[2].colorize(:light_green) when 'C' then repo[2] = repo[2].black when 'Go' then repo[2] = repo[2].yellow when 'Assembly', 'Java', 'JavaScript' then repo[2] = repo[2].colorize(:light_yellow) when 'Common Lisp' then repo[2] = repo[2].cyan end repo[4] = repo[4].to_s.blue repo[3] = repo[3].red repo[5] = repo[5].time_ago_in_words repo[6] = "github.com/#{repo[3].uncolorize}/#{repo[0].uncolorize}".magenta repo end # Add separators repos = repos.product([:separator]).flatten(1)[0...-1] # Construct the table table = Terminal::Table.new table.headings = ['Name', 'Description', 'Language', 'Author', 'Stars', 'Last Updated', ENV['_system_name'] == 'OSX' ? 'Link (⌘ + Click)' : 'Link'] table.rows = repos[0..20] table.style = { width: `/usr/bin/env tput cols`.to_i } # Print the table puts "\n#{table}\n\n" else puts "\nNo results for that query.\n\n" end else puts "\nNo results found. Have you starred any repos? Have you exceeded your rate limit?\n\n" end end |
Class Method Details
.refresh ⇒ Object
133 134 135 136 |
# File 'lib/galileo.rb', line 133 def self.refresh FileUtils.rm_rf(Dir.tmpdir) self.new([]) end |