From bde51b4a2fc3be1fdab756c96b1f866c150b2c94 Mon Sep 17 00:00:00 2001 From: drammopo Date: Mon, 17 Feb 2014 01:05:08 -0800 Subject: [PATCH 1/7] Watchman assignment submission. --- db/seed.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..2834206 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -3,5 +3,14 @@ Show.delete_all amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") +cine = Network.create(name: "Cinemax") +usa = Network.create(name: "USA Network") +netflix = Network.create(name: "Netflix") +sho = Network.create(name: "Showtime") Show.create(name: "Mad Men", day_of_week: "Sunday", hour_of_day: 22, network: amc) Show.create(name: "Community", day_of_week: "Thursday", hour_of_day: 20, network: nbc) +Show.create(name: "Breaking Bad", day_of_week: "Sunday", hour_of_day: 22, network: amc) +Show.create(name: "Banshee", day_of_week: "Friday", hour_of_day: 22, network: cine) +Show.create(name: "Suits", day_of_week: "Thursday", hour_of_day: 21, network: usa) +Show.create(name: "House of Cards", day_of_week: "Friday", hour_of_day: 20, network: netflix) +Show.create(name: "House of Lies", day_of_week: "Sunday", hour_of_day: 22, network: sho) From d29f4a2632f4126538d48fde3f4baed7a5e55cf7 Mon Sep 17 00:00:00 2001 From: drammopo Date: Mon, 17 Feb 2014 06:45:29 -0800 Subject: [PATCH 2/7] Added Eagle level features. --- db/migrate/20140217_create_beers.rb | 14 ++++++++++++++ db/seed.rb | 9 +++++++++ models/beer.rb | 11 +++++++++++ models/show.rb | 4 ++++ watchman.rb | 14 ++++++++++++++ 5 files changed, 52 insertions(+) create mode 100644 db/migrate/20140217_create_beers.rb create mode 100644 models/beer.rb diff --git a/db/migrate/20140217_create_beers.rb b/db/migrate/20140217_create_beers.rb new file mode 100644 index 0000000..6d1c265 --- /dev/null +++ b/db/migrate/20140217_create_beers.rb @@ -0,0 +1,14 @@ +class Beer ActiveRecord::Migration + + def change + create_table :beers do |t| + t.string :name + t.string :country + t.string :brewer + t.string :kind_of + t.float :rating + t.text :summary + t.timestamps + end + end +end \ No newline at end of file diff --git a/db/seed.rb b/db/seed.rb index 2834206..688a70b 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -14,3 +14,12 @@ Show.create(name: "Suits", day_of_week: "Thursday", hour_of_day: 21, network: usa) Show.create(name: "House of Cards", day_of_week: "Friday", hour_of_day: 20, network: netflix) Show.create(name: "House of Lies", day_of_week: "Sunday", hour_of_day: 22, network: sho) + +# Beer.create('Nova Shin', 'Brazil', 'Foo', 'Pilsner', 4, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +# Beer.create('Tusker', 'Kenya', 'Kenya Breweries', 'Lager', 4, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +# Beer.create('Kiwi', 'New Zealand', 'Foo', 'Lager', 4, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +# Beer.create('VB', 'Kenya', 'Foo', 'Lager', 1, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +# Beer.create('Tiger', 'Singapore', 'Foo', 'Lager', 3) +# Beer.create('Sapora', 'Japan', 'Foo', 'Lager', 2, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +# Beer.create('Castle', 'South Africa', 'Foo', 'Lager', 5, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +# Beer.create('Windhoek', 'Namibia', 'Namibia Breweries', 'Lager', 2, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') diff --git a/models/beer.rb b/models/beer.rb new file mode 100644 index 0000000..ef25ff2 --- /dev/null +++ b/models/beer.rb @@ -0,0 +1,11 @@ +class Beer < ActiveRecord::Base + + def to_s + "\"#{name}"\" , [#{kind_of}, #{country}, #{brewer}]" + end + + def summary + "Nova Shin is a Pilsner from Brazil. Did you know? . I rate it a 4.0 out of 5." + "#{name} is a #{kind_of} from #{country}. Did you know?\n #{summary}.\n I rate it a #{rating} out of 5." + end +end \ No newline at end of file diff --git a/models/show.rb b/models/show.rb index 6c82f65..c6ca37f 100644 --- a/models/show.rb +++ b/models/show.rb @@ -3,6 +3,10 @@ class Show < ActiveRecord::Base validates_presence_of :name + def by_day(day_of_week) + Show.where(:day_of_week => day_of_week) + end + def to_s "#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} " end diff --git a/watchman.rb b/watchman.rb index ebe9be4..5cbf5c2 100644 --- a/watchman.rb +++ b/watchman.rb @@ -13,3 +13,17 @@ puts show end end + +prompt = '/>' + '\n' +puts prompt + "On which day would you like to watch TV?" +input = get.chomp +puts prompt + "On #{input.titlecase}s, you can watch:\n" +shows_list = Show.by_day(input) + shows_list.each do |show| + puts "#{show.name} at #{show.hour_of_day} on #{show.network}" + end + +puts "\n----------------------------\n" +Beers.all.each do |beer| + puts beer +end From 5621cf9e9141404c56963b4669e358cd0c42382e Mon Sep 17 00:00:00 2001 From: drammopo Date: Mon, 17 Feb 2014 22:28:26 +0200 Subject: [PATCH 3/7] Added corrections to all levels. --- ..._beers.rb => 201402171619_create_beers.rb} | 8 +++---- db/seed.rb | 18 ++++++++------- models/beer.rb | 9 ++++---- models/show.rb | 4 ++-- watchman.rb | 22 +++++++++++-------- 5 files changed, 33 insertions(+), 28 deletions(-) rename db/migrate/{20140217_create_beers.rb => 201402171619_create_beers.rb} (62%) diff --git a/db/migrate/20140217_create_beers.rb b/db/migrate/201402171619_create_beers.rb similarity index 62% rename from db/migrate/20140217_create_beers.rb rename to db/migrate/201402171619_create_beers.rb index 6d1c265..132f92f 100644 --- a/db/migrate/20140217_create_beers.rb +++ b/db/migrate/201402171619_create_beers.rb @@ -1,4 +1,4 @@ -class Beer ActiveRecord::Migration +class CreateBeers < ActiveRecord::Migration def change create_table :beers do |t| @@ -6,9 +6,9 @@ def change t.string :country t.string :brewer t.string :kind_of - t.float :rating - t.text :summary + t.integer :rating + t.string :summary t.timestamps end end -end \ No newline at end of file +end diff --git a/db/seed.rb b/db/seed.rb index 688a70b..9c2eb66 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,6 +1,7 @@ # Cleaning Out Network.delete_all Show.delete_all + amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") cine = Network.create(name: "Cinemax") @@ -15,11 +16,12 @@ Show.create(name: "House of Cards", day_of_week: "Friday", hour_of_day: 20, network: netflix) Show.create(name: "House of Lies", day_of_week: "Sunday", hour_of_day: 22, network: sho) -# Beer.create('Nova Shin', 'Brazil', 'Foo', 'Pilsner', 4, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') -# Beer.create('Tusker', 'Kenya', 'Kenya Breweries', 'Lager', 4, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') -# Beer.create('Kiwi', 'New Zealand', 'Foo', 'Lager', 4, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') -# Beer.create('VB', 'Kenya', 'Foo', 'Lager', 1, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') -# Beer.create('Tiger', 'Singapore', 'Foo', 'Lager', 3) -# Beer.create('Sapora', 'Japan', 'Foo', 'Lager', 2, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') -# Beer.create('Castle', 'South Africa', 'Foo', 'Lager', 5, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') -# Beer.create('Windhoek', 'Namibia', 'Namibia Breweries', 'Lager', 2, 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +Beer.delete_all +Beer.create(name: 'Nova Schin', country: 'Brazil', brewer: ' Brasil Kirin', kind_of: 'Pilsner', rating: 5, summary:'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed') +Beer.create(name: 'Tusker', country: 'Kenya', brewer: 'East African Breweries', kind_of: 'Lager', rating: 4, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +Beer.create(name: 'Tui', country: 'New Zealand', brewer: 'DB Breweries', kind_of: 'Indian Pale Ale', rating: 4, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +Beer.create(name: 'Victoria Bitter', country: 'Australian', brewer: 'Carlton & United Breweries, Ltd', kind_of: 'Lager', rating: 1, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +Beer.create(name: 'Tiger', country: 'Singapore', brewer: 'Foo', kind_of: 'Lager', rating: 3, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tsummary: incidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +Beer.create(name: 'Sapporo', country: 'Japan', brewer: 'Sapporo Breweries Ltd', kind_of: 'Lager', rating: 2, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +Beer.create(name: 'Castle', country: 'South Africa', brewer: 'South African Breweries Ltd', kind_of: 'Lager', rating: 5, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') +Beer.create(name: 'Windhoek', country: 'Namibia', brewer: 'Namibia Breweries', kind_of: 'Lager', rating: 2, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') diff --git a/models/beer.rb b/models/beer.rb index ef25ff2..dc8101a 100644 --- a/models/beer.rb +++ b/models/beer.rb @@ -1,11 +1,10 @@ class Beer < ActiveRecord::Base def to_s - "\"#{name}"\" , [#{kind_of}, #{country}, #{brewer}]" + "\"#{name}\" , [#{kind_of}, #{country}, #{brewer}]" end - def summary - "Nova Shin is a Pilsner from Brazil. Did you know? . I rate it a 4.0 out of 5." - "#{name} is a #{kind_of} from #{country}. Did you know?\n #{summary}.\n I rate it a #{rating} out of 5." + def summarize + "#{name} is a #{kind_of} from #{country}. Did you know?\n #{summary}.\n I rate it a #{rating} out of 5." end -end \ No newline at end of file +end diff --git a/models/show.rb b/models/show.rb index c6ca37f..7bc0e95 100644 --- a/models/show.rb +++ b/models/show.rb @@ -3,11 +3,11 @@ class Show < ActiveRecord::Base validates_presence_of :name - def by_day(day_of_week) + def self.by_day(day_of_week) Show.where(:day_of_week => day_of_week) end def to_s - "#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} " + "#{name} airs at #{hour_of_day}:00 #{day_of_week} on #{network} " end end diff --git a/watchman.rb b/watchman.rb index 5cbf5c2..a32d018 100644 --- a/watchman.rb +++ b/watchman.rb @@ -5,25 +5,29 @@ Dir.glob('./models/*').each { |r| require r} require "./db/seed" +puts "\n\nPanda Level\n" +puts "----------------------" puts "There are #{Show.count} in the database" Network.all.each do |network| puts "Shows airing on #{network}" network.shows.each do |show| puts show - end + end end -prompt = '/>' + '\n' -puts prompt + "On which day would you like to watch TV?" -input = get.chomp -puts prompt + "On #{input.titlecase}s, you can watch:\n" +puts "\n\nTiger Level\n" +puts "----------------------" +puts "On which day would you like to watch TV?" +input = gets.chomp.titlecase +puts "On #{input.titlecase}s, you can watch:\n" shows_list = Show.by_day(input) shows_list.each do |show| - puts "#{show.name} at #{show.hour_of_day} on #{show.network}" + puts "#{show.name} at #{show.hour_of_day}:00 on #{show.network}" end -puts "\n----------------------------\n" -Beers.all.each do |beer| - puts beer +puts "\n\nEagle (Advanced) Level\n" +puts "----------------------" +Beer.all.each do |beer| + puts beer end From 779c2b6de7ba770ce95396c23c065101766d8cc4 Mon Sep 17 00:00:00 2001 From: drammopo Date: Tue, 18 Feb 2014 01:10:16 -0800 Subject: [PATCH 4/7] Added final features to assignment. --- models/beer.rb | 2 +- watchman.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/models/beer.rb b/models/beer.rb index dc8101a..2da66ce 100644 --- a/models/beer.rb +++ b/models/beer.rb @@ -5,6 +5,6 @@ def to_s end def summarize - "#{name} is a #{kind_of} from #{country}. Did you know?\n #{summary}.\n I rate it a #{rating} out of 5." + "#{name} is a #{kind_of} from #{country}.\n#{summary}.\nI rate it a #{rating} out of 5." end end diff --git a/watchman.rb b/watchman.rb index a32d018..d644209 100644 --- a/watchman.rb +++ b/watchman.rb @@ -31,3 +31,14 @@ Beer.all.each do |beer| puts beer end + +puts "\n\nWhat would you like to learn more about?" +input = gets.chomp.titlecase + +beer = Beer.find_by_name(input) +if beer + puts "Did you know?\n" + puts beer.summarize +else + puts "Sorry, I can't do that right now." +end From e98ecd6df900f716d5421d325657700446e6c10d Mon Sep 17 00:00:00 2001 From: drammopo Date: Tue, 18 Feb 2014 02:49:54 -0800 Subject: [PATCH 5/7] Moved Beer.delete_all closer to clean-out section of seed.rb. --- db/seed.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/seed.rb b/db/seed.rb index 9c2eb66..707f07f 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,6 +1,7 @@ # Cleaning Out Network.delete_all Show.delete_all +Beer.delete_all amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") @@ -16,7 +17,6 @@ Show.create(name: "House of Cards", day_of_week: "Friday", hour_of_day: 20, network: netflix) Show.create(name: "House of Lies", day_of_week: "Sunday", hour_of_day: 22, network: sho) -Beer.delete_all Beer.create(name: 'Nova Schin', country: 'Brazil', brewer: ' Brasil Kirin', kind_of: 'Pilsner', rating: 5, summary:'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed') Beer.create(name: 'Tusker', country: 'Kenya', brewer: 'East African Breweries', kind_of: 'Lager', rating: 4, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') Beer.create(name: 'Tui', country: 'New Zealand', brewer: 'DB Breweries', kind_of: 'Indian Pale Ale', rating: 4, summary: 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ...') From eb09bf6541a14b1a114508c64eb560831bdc4188 Mon Sep 17 00:00:00 2001 From: drammopo Date: Tue, 18 Feb 2014 17:49:19 +0200 Subject: [PATCH 6/7] Switched to ActiveRecord method call. --- watchman.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/watchman.rb b/watchman.rb index d644209..d0da1b0 100644 --- a/watchman.rb +++ b/watchman.rb @@ -21,8 +21,8 @@ puts "On which day would you like to watch TV?" input = gets.chomp.titlecase puts "On #{input.titlecase}s, you can watch:\n" -shows_list = Show.by_day(input) - shows_list.each do |show| +show_list = Show.find_all_by_day_of_week(input) + show_list.each do |show| puts "#{show.name} at #{show.hour_of_day}:00 on #{show.network}" end @@ -38,7 +38,7 @@ beer = Beer.find_by_name(input) if beer puts "Did you know?\n" - puts beer.summarize + puts beer.summarize else puts "Sorry, I can't do that right now." end From 2467ef18fcc3805e18393ca7a1d10e7aab359d53 Mon Sep 17 00:00:00 2001 From: drammopo Date: Tue, 18 Feb 2014 18:11:21 +0200 Subject: [PATCH 7/7] Switched to Show#where instead of Show#find_by... --- models/show.rb | 4 ---- watchman.rb | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/models/show.rb b/models/show.rb index 7bc0e95..bd12d83 100644 --- a/models/show.rb +++ b/models/show.rb @@ -3,10 +3,6 @@ class Show < ActiveRecord::Base validates_presence_of :name - def self.by_day(day_of_week) - Show.where(:day_of_week => day_of_week) - end - def to_s "#{name} airs at #{hour_of_day}:00 #{day_of_week} on #{network} " end diff --git a/watchman.rb b/watchman.rb index d0da1b0..0be1de0 100644 --- a/watchman.rb +++ b/watchman.rb @@ -21,7 +21,7 @@ puts "On which day would you like to watch TV?" input = gets.chomp.titlecase puts "On #{input.titlecase}s, you can watch:\n" -show_list = Show.find_all_by_day_of_week(input) +show_list = Show.where(day_of_week: "#{input}") show_list.each do |show| puts "#{show.name} at #{show.hour_of_day}:00 on #{show.network}" end