Class: Gitfave::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/gitfave.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username) ⇒ Main

Returns a new instance of Main.



9
10
11
12
# File 'lib/gitfave.rb', line 9

def initialize(username)
	@username = username
	@client = Client.new(@username)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/gitfave.rb', line 7

def client
  @client
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/gitfave.rb', line 7

def username
  @username
end

Instance Method Details

#language_countObject



14
15
16
17
18
# File 'lib/gitfave.rb', line 14

def language_count
	all_repo_languages = @client.user_repositories.map {|repo| repo["language"]}
	languages_used = all_repo_languages.uniq
	languages_used.each.map {|language| {:language => language, :count => all_repo_languages.count(language)}}
end


33
34
35
36
# File 'lib/gitfave.rb', line 33

def print_favourite_language
	favourite = users_favourite_language
	"#{@username}'s favourite language is #{favourite[:language]}, having used it #{favourite[:count]} time(s)"
end

#users_favourite_languageObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gitfave.rb', line 20

def users_favourite_language
	most_popular_count = 0
	most_popular_language = nil
	language_count.each do |lc|
		if lc[:count] > most_popular_count
			most_popular_language = lc
			most_popular_count = lc[:count]
		end
	end

	return most_popular_language
end