class GithubFavoriteLanguage
Constants
- VERSION
Public Class Methods
new(username:)
click to toggle source
# File lib/github_favorite_language.rb, line 4 def initialize(username:) @username = username.strip raise UsernameWhitespaceOrEmpty if @username.empty? @github_api = GithubAPI.new end
print_usage()
click to toggle source
# File lib/github_favorite_language.rb, line 37 def self.print_usage puts %Q( Description: Find out any GitHub user's favorite programming language Usage: github_favorite_language vfonic This will fetch vfonic user repos and return the name of the language with most bytes of code written. For GitHub documentation refer to: https://developer.github.com/v3/ ) end
Public Instance Methods
favorite_language()
click to toggle source
# File lib/github_favorite_language.rb, line 10 def favorite_language repos = @github_api.repos(user: @username) languages = Hash.new(0) repos.map do |repo| languages[repo["language"]] += repo["size"] unless repo["language"].nil? || repo["language"].empty? end languages.max_by { |lang, size| size }.first unless languages.empty? end
print_favorite_language()
click to toggle source
# File lib/github_favorite_language.rb, line 21 def print_favorite_language begin language = favorite_language if language.nil? unless language.nil? print_message(message: "#{@username}'s favorite language is: #{language}") else print_no_public_repos end rescue JsonApiClient::NotFound print_username_not_found rescue JsonApiClient::Error, JsonApiClient::RateLimitExceeded => e print_message(message: e.message) end end
Private Instance Methods
print_message(message:)
click to toggle source
# File lib/github_favorite_language.rb, line 53 def print_message(message:) puts message end
print_no_public_repos()
click to toggle source
# File lib/github_favorite_language.rb, line 57 def print_no_public_repos puts "Couldn't determine #{@username}'s favorite language." puts "Check if #{@username} has public repos with code in them." end
print_username_not_found()
click to toggle source
# File lib/github_favorite_language.rb, line 62 def print_username_not_found puts "User #{@username} not found. Check the username is correct." end