Class: GitGameShow::MiniGame

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

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.descriptionObject

Returns the value of attribute description.



13
14
15
# File 'lib/git_game_show/mini_game.rb', line 13

def description
  @description
end

.exampleObject

Returns the value of attribute example.



13
14
15
# File 'lib/git_game_show/mini_game.rb', line 13

def example
  @example
end

.nameObject

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_roundObject

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

.descendantsObject

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

Raises:

  • (NotImplementedError)


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

Raises:

  • (NotImplementedError)


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 get_commit_authors(commits)
  commits.map { |commit| commit.author.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 get_commit_messages(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