diff --git a/Gemfile b/Gemfile index 416fe44..680f570 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 3d79568..d3964be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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 diff --git a/adventure.rb b/adventure.rb new file mode 100644 index 0000000..4209f7c --- /dev/null +++ b/adventure.rb @@ -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 "------------------------------------------" diff --git a/config/database.yml.sample b/config/database.yml.sample new file mode 100644 index 0000000..2e5c2a9 --- /dev/null +++ b/config/database.yml.sample @@ -0,0 +1,6 @@ +host: 'localhost' +adapter: 'postgresql' +database: 'episode5' +username: XXXXXXX +encoding: 'utf8' +pool: 5 diff --git a/db/migrate/001_creates_page.rb b/db/migrate/001_creates_page.rb new file mode 100644 index 0000000..325cba3 --- /dev/null +++ b/db/migrate/001_creates_page.rb @@ -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 diff --git a/db/seed.rb b/db/seed.rb new file mode 100644 index 0000000..89a99a2 --- /dev/null +++ b/db/seed.rb @@ -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?") diff --git a/db/setup.rb b/db/setup.rb new file mode 100644 index 0000000..0e80690 --- /dev/null +++ b/db/setup.rb @@ -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/") diff --git a/models/book.rb b/models/book.rb new file mode 100644 index 0000000..3c14935 --- /dev/null +++ b/models/book.rb @@ -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 diff --git a/models/page.rb b/models/page.rb new file mode 100644 index 0000000..6ce2772 --- /dev/null +++ b/models/page.rb @@ -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 diff --git a/my_picks.yml b/my_picks.yml new file mode 100644 index 0000000..1b25027 --- /dev/null +++ b/my_picks.yml @@ -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 \ No newline at end of file diff --git a/spec/.gitkeep b/spec/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/spec/book_spec.rb b/spec/book_spec.rb new file mode 100644 index 0000000..ad0a4b7 --- /dev/null +++ b/spec/book_spec.rb @@ -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 diff --git a/spec/page_spec.rb b/spec/page_spec.rb new file mode 100644 index 0000000..6af65f5 --- /dev/null +++ b/spec/page_spec.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..bdb95b8 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,5 @@ +require "rspec" +require 'bundler/setup' +require_relative '../db/setup' +require_relative "../models/page" +require_relative "../models/book" diff --git a/theweb.rb b/theweb.rb index a531ce4..caea9a8 100644 --- a/theweb.rb +++ b/theweb.rb @@ -2,10 +2,16 @@ require 'bundler/setup' require 'sinatra' require 'sinatra/reloader' +require 'yaml' + +require_relative 'db/setup' +require_relative 'models/page' +require_relative 'models/book' +require "./db/seed" enable :sessions -get '/' do - erb :dashboard +get '/number' do + erb :number end post '/number' do @@ -16,3 +22,52 @@ @the_number = rand(number_as_string) erb :number end + +get '/' do + my_picks ||= Picks.get_picks + @featured_pick = my_picks.sample + erb :about +end + +get '/adventure' do + @page = Page.starting_point + @book = Book.new(@page) + session[:book] = @book + erb :adventure +end + +get '/adventure/my_game' do + erb :"adventure/my_game" +end + +post '/adventure/my_game' do + selected_option = params.fetch('selected_option') + session[:book].input(selected_option) + if session[:book].complete_game? + erb :"adventure/complete" + else + redirect :"adventure/my_game" + end +end + +get '/adventure/complete' do + erb :"adventure/complete" +end + +class Picks + @@picks = [] + def self.get_picks + YAML.load(File.read("./my_picks.yml")) + end +end + + + + + + + + + + + diff --git a/views/about.erb b/views/about.erb new file mode 100644 index 0000000..8ff33ff --- /dev/null +++ b/views/about.erb @@ -0,0 +1,42 @@ + +
+ My name is Jason. I’ve been in the role of Business Analyst for over 10 years now. +
++ I didn’t set out to be a Business Analyst. In fact, I was initially a fine arts major. I like drawing pictures and thought it’d be cool to draw illustrations for a living… but things change, and I switched to a general business major. +
++ I've always enjoyed solving the tough problems thrown my way as an analyst. There are patterns that are predictable, but there's always enough variability to keep it interesting. It's a bit like solving a puzzle. +
+by <%= @featured_pick["author"] %>
++ <%= @featured_pick["description"] %> +
+<%= session[:book].current_page.content %>
+ + +<%= session[:book].current_page.content %>
++ Play Again +
+<%= session[:book].current_page.content %>
+ + +Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
- -Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui.
- -Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.
- -Number of Randoms: <%= @number_of_randoms %>
+ +