Class: GitGameShow::MiniGame
- Inherits:
-
Object
- Object
- GitGameShow::MiniGame
- Defined in:
- lib/git_game_show/mini_game.rb
Class Attribute Summary collapse
-
.description ⇒ Object
Returns the value of attribute description.
-
.example ⇒ Object
Returns the value of attribute example.
-
.name ⇒ Object
Returns the value of attribute name.
-
.questions_per_round ⇒ Object
Returns the value of attribute questions_per_round.
Class Method Summary collapse
-
.descendants ⇒ Object
Keep track of all subclasses (mini games).
- .inherited(subclass) ⇒ Object
Instance Method Summary collapse
-
#evaluate_answers(question, player_answers) ⇒ Object
Method to evaluate player answers and return results This should be overridden by subclasses.
-
#generate_questions(repo) ⇒ Object
Method to generate questions based on Git repo data This should be overridden by subclasses.
-
#get_all_commits(repo) ⇒ Object
Helper method to get all commits from a repo.
-
#get_commit_authors(commits) ⇒ Object
Helper method to get unique authors from commits.
-
#get_commit_messages(commits) ⇒ Object
Helper method to get commit messages.
-
#shuffled_excluding(array, exclude = nil) ⇒ Object
Helper method to shuffle an array with the option to exclude certain items.
Class Attribute Details
.description ⇒ Object
Returns the value of attribute description.
13 14 15 |
# File 'lib/git_game_show/mini_game.rb', line 13 def description @description end |
.example ⇒ Object
Returns the value of attribute example.
13 14 15 |
# File 'lib/git_game_show/mini_game.rb', line 13 def example @example end |
.name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/git_game_show/mini_game.rb', line 13 def name @name end |
.questions_per_round ⇒ Object
Returns the value of attribute questions_per_round.
13 14 15 |
# File 'lib/git_game_show/mini_game.rb', line 13 def questions_per_round @questions_per_round end |
Class Method Details
.descendants ⇒ Object
Keep track of all subclasses (mini games)
5 6 7 |
# File 'lib/git_game_show/mini_game.rb', line 5 def descendants @descendants ||= [] end |
.inherited(subclass) ⇒ Object
9 10 11 |
# File 'lib/git_game_show/mini_game.rb', line 9 def inherited(subclass) descendants << subclass end |
Instance Method Details
#evaluate_answers(question, player_answers) ⇒ Object
Method to evaluate player answers and return results This should be overridden by subclasses
31 32 33 |
# File 'lib/git_game_show/mini_game.rb', line 31 def evaluate_answers(question, player_answers) raise NotImplementedError, "#{self.class} must implement #evaluate_answers" end |
#generate_questions(repo) ⇒ Object
Method to generate questions based on Git repo data This should be overridden by subclasses
25 26 27 |
# File 'lib/git_game_show/mini_game.rb', line 25 def generate_questions(repo) raise NotImplementedError, "#{self.class} must implement #generate_questions" end |
#get_all_commits(repo) ⇒ Object
Helper method to get all commits from a repo
36 37 38 39 |
# File 'lib/git_game_show/mini_game.rb', line 36 def get_all_commits(repo) # Get a larger number of commits to ensure more diversity repo.log(1000).each.to_a end |
#get_commit_authors(commits) ⇒ Object
Helper method to get unique authors from commits
42 43 44 |
# File 'lib/git_game_show/mini_game.rb', line 42 def (commits) commits.map { |commit| commit..name }.uniq end |
#get_commit_messages(commits) ⇒ Object
Helper method to get commit messages
47 48 49 |
# File 'lib/git_game_show/mini_game.rb', line 47 def (commits) commits.map(&:message) end |
#shuffled_excluding(array, exclude = nil) ⇒ Object
Helper method to shuffle an array with the option to exclude certain items
52 53 54 55 |
# File 'lib/git_game_show/mini_game.rb', line 52 def shuffled_excluding(array, exclude = nil) items = exclude ? array.reject { |item| item == exclude } : array.dup items.shuffle end |