module Mathangman::Utility

Public Instance Methods

check_source(addy) click to toggle source
# File lib/mathangman/utility.rb, line 38
def check_source(addy)
   address = File.join(File.dirname(File.expand_path(__FILE__)))[0..-15] + addy
   # require "pry";  binding.pry
  if File.exist?(address)
    # require "pry";   binding.pry
    dict = File.readlines address

    new_dict = []
    dict.each { | item | new_dict << item.to_s }
    new_dict
  else
    # p "hello"
    puts Display.no_source
    exit
  end
end
is_alpha?(char) click to toggle source
# File lib/mathangman/utility.rb, line 55
def is_alpha?(char)
  if char.length > 1
    true if char.match(/^[[:alpha:]]+$/) != nil
  else
    true if char.match(/^[[:alpha:]]$/) != nil
  end
end
quit_reply(obj = nil) click to toggle source
# File lib/mathangman/utility.rb, line 16
def quit_reply(obj = nil)
  reply = gets.chomp.downcase
  if reply == "y" || reply == "yes"
    if obj != nil && obj != "pre_game"
      puts Display.save_notice
      save_on_quit(obj)
    end
  elsif reply != "y" && reply != "yes" && obj == "pre_game"
    puts "       *       Choose a difficulty level to continue.   *"
    obj.check_difficulty
  elsif reply != "y" && reply != "yes" && obj != "pre_game" && (is_alpha? reply)
    obj.guesses
  end
end
quitter(obj = nil) click to toggle source
# File lib/mathangman/utility.rb, line 5
def quitter(obj = nil)
  if obj == "force"
    exit
  else
    puts Display.confirm_quit
    quit_reply(obj)
    puts Display.quit_notice
    exit
  end
end
save_on_quit(obj) click to toggle source
# File lib/mathangman/utility.rb, line 31
def save_on_quit(obj)
  save_it = gets.chomp.downcase
    if save_it == 'y' || save_it == "yes"
      obj.save_game
    end
end