class Ghstars::CLI
Public Instance Methods
is_numeric?(input)
click to toggle source
# File lib/ghstars/cli.rb, line 54 def is_numeric?(input) input.to_f.to_s == input.to_s || input.to_i.to_s == input.to_s end
list(top_repos=0)
click to toggle source
# File lib/ghstars/cli.rb, line 44 def list(top_repos=0) top_repos = top_repos.to_i if is_numeric?(top_repos) puts "Fetching repositories, please hold..." if options[:verbose] query = {visibility: 'public', affiliation: 'owner'} repos = Ghstars.get_repos(query: query) repos = repos[0..(top_repos-1)] if top_repos > 0 puts tabelize(repos, top_repos) end
show()
click to toggle source
# File lib/ghstars/cli.rb, line 22 def show puts "Fetching repositories, please hold..." if options[:verbose] query = {visibility: 'public', affiliation: 'owner'} repos = Ghstars.get_repos(query: query) star_count = repos.map{|r| r[:stargazers_count]}.sum if options[:verbose] puts "You have #{star_count} #{star_count > 1 ? "stars" : "star"}" else puts star_count end end
tabelize(repos, top_repos)
click to toggle source
# File lib/ghstars/cli.rb, line 58 def tabelize(repos, top_repos) star_count = repos.map{|r| r[:stargazers_count]}.sum footer_text = top_repos > 0 ? "Total count of selection" : "Total count" table = Terminal::Table.new do |t| t.add_row [ {value: '#'}, {value: 'Name of Repository'}, {value: 'Star'} ] t.add_separator repos.each_with_index do |repo, index| t.add_row [ {value: index+1}, {value: repo[:full_name]}, {value: repo[:stargazers_count], alignment: :right} ] end end table.add_separator table.add_row ['', {value: footer_text}, {value: star_count, alignment: :right}] table end
version()
click to toggle source
# File lib/ghstars/cli.rb, line 10 def version puts Ghstars::VERSION end