module PaitinHangman::SimpleMethods

Public Instance Methods

choice_integrity() click to toggle source
# File lib/paitin_hangman/simple_methods.rb, line 53
def choice_integrity
  choice = gets.chomp.downcase
  until choice == "r" || choice == "q" || choice == "quit"
    puts "You must enter either a 'r' or 'q' or type 'quit'"
    choice = STDIN.gets.chomp.downcase
  end
  decide(choice)
end
decide(choice) click to toggle source
# File lib/paitin_hangman/simple_methods.rb, line 62
def decide(choice)
  if choice == "r"
    @player1 ? Paitin.new.play(@player1) : Paitin.new.play(@player2)
  else
    exit
  end
end
length_one?(parameter) click to toggle source
# File lib/paitin_hangman/simple_methods.rb, line 26
def length_one?(parameter)
  if parameter.length == 1
    return true
  else
    puts "Enter just one letter or an hyphen or an apostrophe"
    return false
  end
end
number?(parameter) click to toggle source
# File lib/paitin_hangman/simple_methods.rb, line 44
def number?(parameter)
  if parameter.scan(/\d/).empty?
    return true
  else
    puts "You cannot enter a number! Try again"
    return false
  end
end
option_integrity() click to toggle source

> The method makes sure a valid option is picked

# File lib/paitin_hangman/simple_methods.rb, line 17
def option_integrity
  @option = gets.chomp
  until @option == "1" || @option == "2"
    puts "Enter either a '1' or a '2'"
    @option = STDIN.gets.chomp
  end
  @option
end
unique?(parameter) click to toggle source
# File lib/paitin_hangman/simple_methods.rb, line 35
def unique?(parameter)
  if @misses.include?(parameter) || @right_guesses.include?(parameter)
    puts "You have used #{parameter} already, try again"
    return false
  else
    return true
  end
end
verify_name_integrity() click to toggle source

> This method verifies the integrity of names

# File lib/paitin_hangman/simple_methods.rb, line 6
def verify_name_integrity
  name = gets.chomp.upcase.strip
  while name.scan(/[^A-Z\s-]/).empty? == false || name.empty? # => It scans for anything other than a letter, a space or a dash
    Message.verify_name
    name = STDIN.gets.chomp.upcase.strip
  end
  name
end