class Object

Public Instance Methods

add_monster(monsters_array) click to toggle source
# File lib/add_monster.rb, line 11
def add_monster(monsters_array)
    info = true
    
    while info == true
      system 'clear'
      puts '-'.colorize(:light_red) * 45
      puts "What is the name of the monster?"
      print '> '
      monster_name = gets.chomp 
      puts '-'.colorize(:light_red) * 45
      puts "Where was the monster sighted?"
      print '> '
      monster_location = gets.chomp
      puts '-'.colorize(:light_red) * 45
      puts "What does the monster look like?"
      print '> '
      monster_description = gets.chomp
      puts '-'.colorize(:light_red) * 45
      puts "Is your entry correct?"
      puts "1. Yes => Add entry to encyclopedia"
      puts "2. No  => Cancel entry return to menu"
      while info == true
        case gets.chomp.to_i
        when 1
          new_monster = Monster.new(monster_name, monster_location, monster_description)
          monsters_array << new_monster
          CSV.open("data.csv", "ab") do |csv|
            csv << [monster_name, monster_location, monster_description]
            system 'clear'
            info = false
          end
        when 2
          system 'clear'
          info = false
        else
          puts "Please pick 1 or 2"
        end
      end
    end
  end
exit_program() click to toggle source
# File lib/invalid_and_exit.rb, line 11
def exit_program()
    system 'clear'
    puts '-'.colorize(:light_red) * 45
    puts "Thankyou for using the Monster Encyclopedia!"
    puts '-'.colorize(:light_red) * 45
    text = Artii::Base.new :font => 'epic'
    puts text.asciify('--M:E--').colorize(:color => :black, :background => :red)
    puts '-'.colorize(:light_red) * 45
    sleep 3.0
    system "clear"
    exit
end
invalid_input() click to toggle source
# File lib/invalid_and_exit.rb, line 2
def invalid_input
    system 'clear'
    puts '-'.colorize(:light_red) * 45
    puts "Please pick a number from the menu."
    puts '-'.colorize(:light_red) * 45
    sleep 3.0
    system 'clear'
end
menu() click to toggle source
remove_monster(monsters_array) click to toggle source
# File lib/remove_monster.rb, line 1
def remove_monster(monsters_array)
  monster = []
  monster_names = []
  csv_text = File.read('data.csv')
  csv = CSV.parse(csv_text, :headers => true)
  csv.each do |row|
    monster << row.to_hash
  end

  system 'clear'

  monster.sort_by! { |mon| mon["name"]}
  monster.each do |thing|
    puts '-'.colorize(:red) * 45
    puts "Name: #{thing["name"]}"
    puts
    monster_names << thing["name"]
  end

  puts "Which monster would you like to remove from the encyclopedia?"
  input = gets.chomp

  if monster_names.include?(input)
    table = CSV.table("data.csv")
    table.delete_if.with_index  do |row, index|
      next if index.zero?
      row[0] == input
    end

    File.open("data.csv", 'w') do |data|
      data.write(table.to_csv)
    end
    system 'clear'
    puts '-'.colorize(:red) * 45
    puts "#{input} was deleted!"
    puts '-'.colorize(:red) * 45
    sleep 2
  else
    system 'clear'
    puts '-'.colorize(:red) * 45
    puts "No monster by that name..."
    puts '-'.colorize(:red) * 45
    sleep 2
  end
end
view_monsters() click to toggle source
# File lib/view_monsters.rb, line 2
def view_monsters()
    monsters_array = []
    csv_text = File.read('data.csv')
    csv = CSV.parse(csv_text, :headers => true)
    csv.each do |row|
      monster = row.to_hash
      monsters_array << monster
      system 'clear'
    end
      monsters_array.sort_by! { |mon| mon["name"]}
      monsters_array.each do |monster|
      puts '-'.colorize(:red) * 45
      puts "Name:" + " #{monster["name"]}".colorize(:light_red)
      puts "Found: #{monster["location"]}"
      puts
      puts "Description: #{monster["description"]}"  
      puts
    end 
    gets
  end