mirror of
https://github.com/kingomarnajjar/amazon.git
synced 2026-07-25 22:27:28 +10:00
working version
This commit is contained in:
parent
7c1c0f2836
commit
76b416e96a
1 changed files with 243 additions and 70 deletions
313
shitty_amazon.rb
313
shitty_amazon.rb
|
|
@ -6,30 +6,31 @@
|
||||||
#
|
#
|
||||||
# 3 groups chosen by Jamie will present their ideas
|
# 3 groups chosen by Jamie will present their ideas
|
||||||
|
|
||||||
|
system("clear")
|
||||||
|
|
||||||
class Book
|
class Book
|
||||||
|
|
||||||
def initialize(name, author, genre)
|
def initialize(title, author, genre)
|
||||||
@name = name
|
@title = title
|
||||||
@author = author
|
@author = author
|
||||||
@genre = genre
|
@genre = genre
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :name, :author, :genre
|
attr_accessor :title, :author, :genre
|
||||||
|
|
||||||
def self.all #this points to all objects in itself (ie the class Song)
|
def self.all #this points to all objects in itself (ie the class Book)
|
||||||
ObjectSpace.each_object(self).to_a #This grabs every object from the Song class and puts it into an array
|
ObjectSpace.each_object(self).to_a #This grabs every object from the Book class and puts it into an array
|
||||||
end
|
end
|
||||||
|
end # end book class
|
||||||
end
|
|
||||||
|
|
||||||
class Genre
|
class Genre
|
||||||
|
|
||||||
def initialize(name)
|
def initialize(type)
|
||||||
@name = name
|
@type = type
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :name
|
attr_accessor :type
|
||||||
end
|
end # end genre class
|
||||||
|
|
||||||
class Author
|
class Author
|
||||||
|
|
||||||
|
|
@ -38,19 +39,19 @@ class Author
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
end
|
end # end author class
|
||||||
|
|
||||||
romance = Genre.new("Romance")
|
romance = Genre.new("Romance")
|
||||||
scifi = Genre.new("Sci-fi")
|
scifi = Genre.new("Sci-fi")
|
||||||
fantasy = Genre.new("Fantasy")
|
fantasy = Genre.new("Fantasy")
|
||||||
|
|
||||||
# romance authors
|
# romance authors
|
||||||
nora_roberts = Author.new("Nora Roberts")
|
roberts = Author.new("Nora Roberts")
|
||||||
jane_austen = Author.new("Jane Austen")
|
austen = Author.new("Jane Austen")
|
||||||
julie_garwood = Author.new("Julie Garwood")
|
garwood = Author.new("Julie Garwood")
|
||||||
|
|
||||||
# fantasy authors
|
# fantasy authors
|
||||||
tolkien = Author.new("J.R.R Tolkien")
|
tolkien = Author.new("J.R.R. Tolkien")
|
||||||
martin = Author.new("George R.R. Martin")
|
martin = Author.new("George R.R. Martin")
|
||||||
king = Author.new("Stephen King")
|
king = Author.new("Stephen King")
|
||||||
|
|
||||||
|
|
@ -60,15 +61,15 @@ asimov = Author.new("Isaac Asimov")
|
||||||
bradbury = Author.new("Ray Bradbury")
|
bradbury = Author.new("Ray Bradbury")
|
||||||
|
|
||||||
# romance books
|
# romance books
|
||||||
Book.new("The Next Always", nora_roberts, romance)
|
Book.new("The Next Always", roberts, romance)
|
||||||
Book.new("Playing the Odds", nora_roberts, romance)
|
Book.new("Playing the Odds", roberts, romance)
|
||||||
Book.new("One man's art", nora_roberts, romance)
|
Book.new("One man's art", roberts, romance)
|
||||||
Book.new("Pride and Prejudice", jane_austen, romance)
|
Book.new("Pride and Prejudice", austen, romance)
|
||||||
Book.new("Emma", jane_austen, romance)
|
Book.new("Emma", austen, romance)
|
||||||
Book.new("Persuasion", jane_austen, romance)
|
Book.new("Persuasion", austen, romance)
|
||||||
Book.new("Shadow Dance", julie_garwood, romance)
|
Book.new("Shadow Dance", garwood, romance)
|
||||||
Book.new("Shadow Music", julie_garwood, romance)
|
Book.new("Shadow Music", garwood, romance)
|
||||||
Book.new("The Lion's Lady", julie_garwood, romance)
|
Book.new("The Lion's Lady", garwood, romance)
|
||||||
|
|
||||||
# fantasy books
|
# fantasy books
|
||||||
Book.new("The Hobbit", tolkien, fantasy)
|
Book.new("The Hobbit", tolkien, fantasy)
|
||||||
|
|
@ -81,7 +82,7 @@ Book.new("The Shining", king, fantasy)
|
||||||
Book.new("Carrie", king, fantasy)
|
Book.new("Carrie", king, fantasy)
|
||||||
Book.new("Misery", king, fantasy)
|
Book.new("Misery", king, fantasy)
|
||||||
|
|
||||||
#scifi
|
# scifi books
|
||||||
Book.new("A Scanner Darkly", dick, scifi)
|
Book.new("A Scanner Darkly", dick, scifi)
|
||||||
Book.new("The Man in the High Castle", dick, scifi)
|
Book.new("The Man in the High Castle", dick, scifi)
|
||||||
Book.new("A Maze of Death", dick, scifi)
|
Book.new("A Maze of Death", dick, scifi)
|
||||||
|
|
@ -92,11 +93,147 @@ Book.new("Fahrenheit 451", bradbury, scifi)
|
||||||
Book.new("The Martian Chronicles", bradbury, scifi)
|
Book.new("The Martian Chronicles", bradbury, scifi)
|
||||||
Book.new("The Illustrated Man", bradbury, scifi)
|
Book.new("The Illustrated Man", bradbury, scifi)
|
||||||
|
|
||||||
|
def classification
|
||||||
|
puts "Would you like [1] fantasy, [2] sci-fi, or [3] romance?"
|
||||||
|
user = gets.chomp
|
||||||
|
|
||||||
|
valid = 0
|
||||||
|
while valid == 0
|
||||||
|
case user
|
||||||
|
when "1"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.genre.type == "Fantasy"
|
||||||
|
print a.title + " by "
|
||||||
|
puts a.author.name
|
||||||
|
puts
|
||||||
|
end # end if statement
|
||||||
|
end # end book loop
|
||||||
|
break # this breaks the loop
|
||||||
|
|
||||||
|
when "2"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.genre.type == "Sci-fi"
|
||||||
|
print a.title + " by "
|
||||||
|
puts a.author.name
|
||||||
|
puts
|
||||||
|
end # end if statement
|
||||||
|
end # end book loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "3"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.genre.type == "Romance"
|
||||||
|
print a.title + " by "
|
||||||
|
puts a.author.name
|
||||||
|
puts
|
||||||
|
end # end if statement
|
||||||
|
end # end book loop
|
||||||
|
break
|
||||||
|
|
||||||
|
else
|
||||||
|
puts "I don't understand"
|
||||||
|
user = gets.chomp
|
||||||
|
end # end case statement
|
||||||
|
end # end while loop
|
||||||
|
|
||||||
|
end # end classification method
|
||||||
|
|
||||||
|
def writer
|
||||||
|
puts "Which of the following authors would you like to choose?"
|
||||||
|
puts "[1] Nora Roberts [2] Jane Austen [3] Julie Garwood"
|
||||||
|
puts "[4] J.R.R. Tolkien [5] George R.R. Martin [6] Stephen King"
|
||||||
|
puts "[7] Philip K. Dick [8] Isaac Asimov [9] Ray Bradbury"
|
||||||
|
user = gets.chomp
|
||||||
|
|
||||||
|
valid = 0
|
||||||
|
while valid == 0
|
||||||
|
case user
|
||||||
|
when "1"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "Nora Roberts"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "2"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "Jane Austen"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "3"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "Julie Garwood"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "4"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "J.R.R. Tolkien"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "5"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "George R.R. Martin"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "6"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "Stephen King"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "7"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "Julie Garwood"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "8"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "Isaac Asimov"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
when "9"
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.author.name == "Ray Bradbury"
|
||||||
|
puts a.title
|
||||||
|
end # end if/else statement
|
||||||
|
end # end book array loop
|
||||||
|
break
|
||||||
|
|
||||||
|
else
|
||||||
|
puts "I don't understand"
|
||||||
|
user = gets.chomp
|
||||||
|
end # end case statement
|
||||||
|
end # end while loop
|
||||||
|
end # end writer method
|
||||||
|
|
||||||
|
# This quiz method is used for recommending books to the user. It asks the user questions and
|
||||||
|
# recommends books based on the user's answers.
|
||||||
|
# Every answer is biased to a particular genre. Each answer will add 1 to a genre tally.
|
||||||
|
# The genre with the highest tally will be recommended. Each genre starts at 0.
|
||||||
@fantasy = 0
|
@fantasy = 0
|
||||||
@scifi= 0
|
@scifi= 0
|
||||||
@romance = 0
|
@romance = 0
|
||||||
|
|
||||||
|
|
||||||
def quiz
|
def quiz
|
||||||
|
|
||||||
valid = 0
|
valid = 0
|
||||||
|
|
@ -104,58 +241,94 @@ def quiz
|
||||||
case @input
|
case @input
|
||||||
when "1"
|
when "1"
|
||||||
@fantasy += 1
|
@fantasy += 1
|
||||||
valid = 1
|
break
|
||||||
|
|
||||||
when "2"
|
when "2"
|
||||||
@scifi += 1
|
@scifi += 1
|
||||||
valid = 1
|
break
|
||||||
|
|
||||||
when "3"
|
when "3"
|
||||||
@romance += 1
|
@romance += 1
|
||||||
valid = 1
|
break
|
||||||
|
|
||||||
else
|
else
|
||||||
puts "I don't understand"
|
puts "I don't understand"
|
||||||
@input = gets.chomp
|
@input = gets.chomp
|
||||||
valid = 0
|
end # end case statement
|
||||||
end
|
end # end while loop
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
end # end quiz method
|
||||||
|
|
||||||
|
# run this method when user chooses recommendation
|
||||||
|
def recommendation
|
||||||
|
|
||||||
|
puts "We would like to know more about you, please answer the following"
|
||||||
|
|
||||||
|
puts "Which of the following do you like the best?"
|
||||||
|
puts "[1] dragons, [2] spaceships, [3] a hot guy/chick"
|
||||||
|
@input = gets.chomp
|
||||||
|
quiz
|
||||||
|
puts "Which one is your favourite"
|
||||||
|
puts "[1] broomstick, [2] aliens, [3] kissing"
|
||||||
|
@input = gets.chomp
|
||||||
|
quiz
|
||||||
|
puts "Which character do you want to be?"
|
||||||
|
puts "[1] elf, [2] astronaut, [3] damsel"
|
||||||
|
@input = gets.chomp
|
||||||
|
quiz
|
||||||
|
puts "When you die, where do you want to go"
|
||||||
|
puts "[1] dungeon, [2] space, [3] bed ;)"
|
||||||
|
@input = gets.chomp
|
||||||
|
quiz
|
||||||
|
|
||||||
|
# After the tally's been added up, they're pushed into the tally_array
|
||||||
|
tally_array = []
|
||||||
|
tally_array << @fantasy << @scifi << @romance
|
||||||
|
|
||||||
|
genre_array = ["Fantasy", "Sci-fi", "Romance"]
|
||||||
|
|
||||||
|
puts
|
||||||
|
puts tally_array
|
||||||
|
puts
|
||||||
|
|
||||||
|
# This finds the genre with the highest tally and assign it as category
|
||||||
|
category = genre_array[tally_array.index(tally_array.max)]
|
||||||
|
puts category
|
||||||
|
puts
|
||||||
|
|
||||||
|
# This array loop looks for books with the genre with the highest tally
|
||||||
|
Book.all.each do |a|
|
||||||
|
if a.genre.type == category
|
||||||
|
print a.title + " by "
|
||||||
|
puts a.author.name
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
end # end book array loop
|
||||||
|
|
||||||
|
end # end recommendation method
|
||||||
|
|
||||||
|
# Program starts here
|
||||||
puts "Hello, welcome to amazin Amazon!"
|
puts "Hello, welcome to amazin Amazon!"
|
||||||
puts "We would like to know more about you, please answer the following"
|
puts "Would you like to browse by [1] genre, [2] author, or see our [3] recommendation?"
|
||||||
|
user = gets.chomp
|
||||||
|
|
||||||
puts "Which of the following do you like the best?"
|
valid = 0
|
||||||
puts "[1] dragons, [2]spaceships, [3]some hot guy"
|
while valid == 0
|
||||||
@input = gets.chomp
|
case user
|
||||||
|
when "1"
|
||||||
|
classification
|
||||||
|
break
|
||||||
|
|
||||||
quiz
|
when "2"
|
||||||
puts "Which one is your favourite"
|
writer
|
||||||
puts "[1] broomstick, [2] aliens, [3] kissing"
|
break
|
||||||
@input = gets.chomp
|
|
||||||
quiz
|
|
||||||
puts "Which character do you want to be?"
|
|
||||||
puts "[1] elf, [2] astronaut, [3] damsel"
|
|
||||||
@input = gets.chomp
|
|
||||||
quiz
|
|
||||||
puts "When you die, where do you want to go"
|
|
||||||
puts "[1] dungeon, [2] space, [3] bed"
|
|
||||||
@input = gets.chomp
|
|
||||||
quiz
|
|
||||||
|
|
||||||
tally_array = []
|
when "3"
|
||||||
tally_array << @fantasy
|
recommendation
|
||||||
tally_array << @scifi
|
break
|
||||||
tally_array << @romance
|
|
||||||
|
|
||||||
genre_array = ["fantasy", "scifi", "romance"]
|
else
|
||||||
|
puts "I don't understand"
|
||||||
puts
|
user = gets.chomp
|
||||||
puts tally_array
|
end # end case statement
|
||||||
puts
|
end # end while loop
|
||||||
|
|
||||||
category = genre_array[tally_array.index(tally_array.max)]
|
|
||||||
puts category
|
|
||||||
|
|
||||||
romance_books = Book.all
|
|
||||||
|
|
||||||
romance_books.each do |book|
|
|
||||||
puts romance_books
|
|
||||||
end
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue