Class: GithubPolyglot
- Inherits:
-
Object
- Object
- GithubPolyglot
- Defined in:
- lib/github_polyglot.rb,
lib/github_polyglot/cli.rb,
lib/github_polyglot/svg.rb,
lib/github_polyglot/svg/language_stats.rb
Overview
Gets language usage stats for a GitHub user.
Defined Under Namespace
Constant Summary collapse
- TOKEN_ENV_VAR =
'GITHUB_TOKEN'
Instance Method Summary collapse
-
#initialize(username: nil, token: nil) ⇒ GithubPolyglot
constructor
A new instance of GithubPolyglot.
-
#json(pretty: false) ⇒ Object
Gets the language stats for the user as JSON.
-
#languages ⇒ Object
Gets language stats for the user.
-
#print ⇒ Object
Prints the languages.
-
#svg ⇒ Object
Generates an SVG string for the languages.
-
#username ⇒ Object
Gets the username to use.
Constructor Details
#initialize(username: nil, token: nil) ⇒ GithubPolyglot
Returns a new instance of GithubPolyglot.
13 14 15 16 17 |
# File 'lib/github_polyglot.rb', line 13 def initialize(username: nil, token: nil) @username = username @token = token @client = Octokit::Client.new(access_token: token) end |
Instance Method Details
#json(pretty: false) ⇒ Object
Gets the language stats for the user as JSON.
42 43 44 45 |
# File 'lib/github_polyglot.rb', line 42 def json(pretty: false) = pretty ? { indent: ' ', space: ' ' } : { indent: '', space: '', array_nl: '', object_nl: '' } JSON.pretty_generate(languages, ) end |
#languages ⇒ Object
Gets language stats for the user.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/github_polyglot.rb', line 28 def languages compiled = Hash.new(0) each_repo do |repo| next if repo[:fork] languages = repo_languages(repo.name) languages.to_h.each_pair do |language, size| compiled[language] += size end end compiled end |
#print ⇒ Object
Prints the languages
48 49 50 51 52 |
# File 'lib/github_polyglot.rb', line 48 def print languages.each_pair do |language, amount| puts "#{language}: #{amount}" end end |
#svg ⇒ Object
Generates an SVG string for the languages
55 56 57 58 |
# File 'lib/github_polyglot.rb', line 55 def svg generator = SVG.new(languages) generator.generate end |
#username ⇒ Object
Gets the username to use.
20 21 22 23 24 25 |
# File 'lib/github_polyglot.rb', line 20 def username return @username unless @username.nil? @username = token_username @username end |