Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panda level submission #12

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
source 'http://rubygems.org'

gem 'rake'
gem 'activerecord'
gem 'activesupport'
gem 'sinatra'
gem 'sinatra-contrib'
gem 'shotgun'
gem 'rspec'
gem 'pg'
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.3)
activesupport (= 3.2.3)
builder (~> 3.0.0)
activerecord (3.2.3)
activemodel (= 3.2.3)
activesupport (= 3.2.3)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activesupport (3.2.3)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
backports (2.5.3)
builder (3.0.0)
diff-lcs (1.2.5)
eventmachine (0.12.10)
i18n (0.6.0)
multi_json (1.3.5)
pg (0.17.1)
rack (1.4.1)
rack-protection (1.2.0)
rack
rack-test (0.6.1)
rack (>= 1.0)
rake (0.9.2.2)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.4)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.4)
shotgun (0.9)
rack (>= 1.0)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
Expand All @@ -26,12 +48,17 @@ GEM
sinatra (~> 1.3.0)
tilt (~> 1.3)
tilt (1.3.3)
tzinfo (0.3.38)

PLATFORMS
ruby

DEPENDENCIES
activerecord
activesupport
pg
rake
rspec
shotgun
sinatra
sinatra-contrib
32 changes: 32 additions & 0 deletions adventure.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rubygems'
require 'bundler/setup'

require_relative 'db/setup'
require_relative 'models/page'
require_relative 'models/book'
require "./db/seed"

page = Page.starting_point
book = Book.new(page)

until book.complete_game? do
puts "------------------------------------------"
puts book.current_page.content
puts "your options: "
puts "A - [#{book.current_page.options.first.preview}]"
puts "B - [#{book.current_page.options.last.preview}]"
puts "What do you want to do? Enter A or B"

book.input( gets )
puts "------------------------------------------"
puts book.current_page.outcome
puts "------------------------------------------"
end
puts book.current_page.content
puts "------------------------------------------"
puts "| |"
puts "| |"
puts "| ADVENTURE COMPLETE |"
puts "| |"
puts "| |"
puts "------------------------------------------"
6 changes: 6 additions & 0 deletions config/database.yml.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
host: 'localhost'
adapter: 'postgresql'
database: 'episode5'
username: XXXXXXX
encoding: 'utf8'
pool: 5
13 changes: 13 additions & 0 deletions db/migrate/001_creates_page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreatesPage < ActiveRecord::Migration
def change
create_table :pages do |t|
t.text :content
t.string :preview
t.string :outcome
t.integer :option_a_id
t.integer :option_b_id
t.boolean :starting_point, default: false
t.boolean :conclusion, default: false
end
end
end
29 changes: 29 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Cleaning Out
Page.delete_all
page_two = Page.create(conclusion: true,
preview: "Go into the forest",
outcome: "You were methodically consumed by ZOMBIE DEER!!!",
content: "As soon as you stepped off the road, darkness consumed you. You tripped, fell to the ground, and a hoard of zombie deer proceeded to gobble you up.")
page_three = Page.create(conclusion: true,
preview: "Walk down the road",
outcome: "You found the circle of life (can be traded at Trapper's Den for 2 gold pieces)!",
content: "Apparently, after receiving it from his father, Simba dropped the circle of life while chasing a zombie deer.")
page_six = Page.create(option_a_id: page_two.id,
option_b_id: page_three.id,
preview: "Take a moment and taste the bacon fat in your mouth",
outcome: "Your spirits are lifted and you are ready to take on the world!",
content: "Armed with the power to take on the known world, you set forth.")
page_four = Page.create(option_a_id: page_six.id,
option_b_id: page_two.id,
preview: "Admire the 30 gold pieces",
outcome: "You were ransacked and robbed by a hoard of geriatric orcs!",
content: "They came at you slow, but because you were sucked into the glow of the gold you didn't notice 3 old orcs guided by walkers(with the little tennis balls on the fronts). You eat the bacon sandwich.")
page_five = Page.create(option_a_id: page_two.id,
option_b_id: page_six.id,
preview: "Eat the bacon sandwich",
outcome: "Your belly is happy and your mind is clear.",
content: "Obviously the only choice. Now that you've chosen wiser than Indiana Jones and the Quest For the Holy Grail, you are left with only the best decisions.")
page = Page.create(starting_point: true,
option_a_id: page_four.id,
option_b_id: page_five.id,
content: "You wake up on a road. It's foggy and damp. In your bag is 30 gold pieces and a bacon sandwich. Which do you choose?")
15 changes: 15 additions & 0 deletions db/setup.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'pg'
require 'active_record'
require 'yaml'

connection_details = YAML::load(File.open('config/database.yml'))

# Setup out connection details
ActiveRecord::Base.establish_connection(connection_details.merge({'database'=> 'postgres', 'schema_search_path'=> 'public'}))
# create the 'tv' database
ActiveRecord::Base.connection.drop_database (connection_details.fetch('database')) rescue nil
ActiveRecord::Base.connection.create_database(connection_details.fetch('database')) rescue nil
# connect to it
ActiveRecord::Base.establish_connection(connection_details)
# Migrate all the things
ActiveRecord::Migrator.migrate("db/migrate/")
21 changes: 21 additions & 0 deletions models/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Book

attr_reader :current_page

def initialize(starting_page)
@current_page = starting_page
end

def input(input_string)
if input_string.chomp == "A"
@current_page = current_page.options.first
elsif input_string.chomp == "B"
@current_page = current_page.options.last
end
end

def complete_game?
current_page.conclusion?
end

end
11 changes: 11 additions & 0 deletions models/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Page < ActiveRecord::Base

def self.starting_point
Page.where(starting_point: true).first
end

def options
Page.find(option_a_id, option_b_id)
end

end
37 changes: 37 additions & 0 deletions my_picks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-
book_name: The New Making of a Cook
author: Madeleine Kamman
description: The Making of a Cook became an instant classic upon its publication in 1971. Since then much has changed in the way America cooks and The New Making of a Cook meets these changes head-on. This fully revised edition teaches every technique used in today's homes and professional kitchens, from julienning vegetables to roasting meats to steaming fish to baking bread. With years of experience teaching America's top chefs how to cook, Madeleine knows what works and why.
url: http://www.amazon.com/The-New-Making-Cook-Techniques/dp/0688152546
image: http://ecx.images-amazon.com/images/I/512WPH9QP0L._SX258_BO1,204,203,200_.jpg
-
book_name: The Food and Life of Oaxaca, Mexico
author: Zarela Martinez
description: The Food and Life of Oaxaca, by New York restaurateur Zarela Martinez, is a fascinating cultural study disguised as a great cookbook. Martinez is part of the new renaissance of Mexican food writers and chefs, including Rick Bayless and Diana Kennedy, who reaffirm that culinary awareness goes hand in hand with cultural awareness.
url: http://www.amazon.com/The-Food-Life-Oaxaca-Mexico/dp/0028603508
image: http://ecx.images-amazon.com/images/I/51za6Qork%2BL._SX258_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg
-
book_name: Larousse Gastronomique
author: Prosper Montagne
description: Since its first publication in 1938, Larousse Gastronomique has been an unparalleled resource. In one volume, it presents the history of foods, eating, and restaurants; cooking terms; techniques from elementary to advanced; a review of basic ingredients with advice on recognizing, buying, storing, and using them; biographies of important culinary figures; and recommendations for cooking nearly everything.

url: http://www.amazon.com/Larousse-Gastronomique-Prosper-Montagne/dp/0609609718
image: http://ecx.images-amazon.com/images/I/41eqmG3PX2L._SY344_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg
-
book_name: Peace, Love, & Barbecue
author: Mike Mills
description: In this unique combination of cookbook, memoir, and travelogue, Mike Mills, the unrivalled king of barbecue, shares his passion for America's favorite cuisine--its intense smoky flavors, its lore and traditions, and its wild cast of characters.
url: http://www.amazon.com/Peace-Love-Barbecue-Recipes-Outright/dp/1594861099
image: http://ecx.images-amazon.com/images/I/51hJChNUmEL._SX258_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg
-
book_name: Authentic Mexican
author: Rick Bayless
description: Americans have at last discovered Mexico's passion for exciting food. We've fallen in love with the great Mexican combination of rich, earthy flavors and casual, festive dining. But we don't begin to imagine how sumptuous and varied the cooking of Mexico really is.
url: http://www.amazon.com/Authentic-Mexican-20th-Anniversary-Ed/dp/0061373265
image: http://ecx.images-amazon.com/images/I/51oZlXhw0NL._SY344_PJlook-inside-v2,TopRight,1,0_SH20_BO1,204,203,200_.jpg
-
book_name: The Art of Cooking Omelettes
author: Madame Romaine De Lyon
description: For 65 years, Madame Romaine de Lyon ran a popular restaurant in midtown New York that served only eggs. But not just any eggs! Mme de Lyon, was a master omelette chef. The walls of her restaurant were covered with signed photos of famous customers, such as Joan Rivers, Mary Tyler Moore, Anne Bancroft, and Mel Brooks (who wrote the screenplay for The Producers at his regular table in the back of the restaurant).
url: http://www.amazon.com/Cooking-Omelettes-Madame-Romaine-Lyon/dp/1626549508
image: http://ecx.images-amazon.com/images/I/51FmlfPHikL._SY344_BO1,204,203,200_.jpg
Empty file added spec/.gitkeep
Empty file.
34 changes: 34 additions & 0 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require_relative "spec_helper"

describe Book do
let!(:option_a) { Page.create }
let!(:option_b) { Page.create }
let!(:page) {Page.create(starting_point: true,
option_a_id: option_a.id,
option_b_id: option_b.id)}
subject { Book.new(page) }

it "should have a page" do
subject.current_page.should eq(page)
end

describe "#input" do
it "should receive input and opens page" do
subject.input("A")
subject.current_page.should eq(option_a)
end
it "should receive input and opens page" do
subject.input("B")
subject.current_page.should eq(option_b)
end

end

describe "#complete_game?" do

it "should know when it's done" do
subject.stub(:current_page) { stub(:conclusion? => true)}
subject.complete_game?.should be_true
end
end
end
52 changes: 52 additions & 0 deletions spec/page_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require_relative "spec_helper"

describe Page do

before(:each) do
Page.delete_all
end

it "should know if it's at the end of the road" do
page = Page.create(conclusion: true)
page.conclusion?.should be_true
end

it "should have awesome content" do
page = Page.create(content: "The fox and hound get along")
Page.find(page.id).content.should eq("The fox and hound get along")
end

it "should have a preview" do
page = Page.create(preview: "Walk down the road")
page.preview.should eq("Walk down the road")
end

it "should be clear about being a winner or a loser" do
page = Page.create(outcome: "You be dead!")
page.outcome.should eq("You be dead!")
end

context "#options" do
let(:option_a) { Page.create }
let(:option_b) { Page.create }
subject {Page.create(option_a_id: option_a.id, option_b_id: option_b.id )}

it "should have options for the next pages" do
subject.options.should eq([option_a, option_b])
end
end

it "should not be a starting point by default" do
Page.create.starting_point.should eq(false)
end
it "should not be a conclusion by default" do
Page.create.conclusion.should eq(false)
end


it "should have a starting point" do
the_page = Page.create(starting_point: true)
Page.starting_point.should eq(the_page)
end

end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rspec"
require 'bundler/setup'
require_relative '../db/setup'
require_relative "../models/page"
require_relative "../models/book"
Loading