From 126928146e8d20efaf48bd4270483971efdfc0a0 Mon Sep 17 00:00:00 2001 From: Elle Yoko Suzuki Date: Mon, 10 Dec 2012 23:51:14 -0800 Subject: [PATCH 1/3] added 2 more shows and outputs shows --- README.md | 2 +- db/seed.rb | 3 +++ watchman.rb | 16 +++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index fce7a09..7ca8f69 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Panda Level ----------- 1. Add 2 more TV shows to the seeds file -2. When I run `ruby watchman.rb`, Have it output all TV shows +2. When I run `ruby watchman.rb`, have it output all TV shows Tiger Level ----------- diff --git a/db/seed.rb b/db/seed.rb index 3c028ff..f0b81ab 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -3,5 +3,8 @@ Show.delete_all amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") +cbs = Network.create(name: "CBS") 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: 'Elementary', day_of_week: 'Thursday', hour_of_day: 22, network: cbs) +Show.create(name: 'Person of Interest', day_of_week: 'Thursday', hour_of_day: 21, network: cbs) diff --git a/watchman.rb b/watchman.rb index ebe9be4..7f15cc1 100644 --- a/watchman.rb +++ b/watchman.rb @@ -7,9 +7,15 @@ 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 +# output by network +#Network.all.each do |network| +# puts "Shows airing on #{network}" +# network.shows.each do |show| +# puts show +# end +#end + +# output all shows +Show.all.each do |show| + puts show end From 870170f3a24cb581e647a7bf17115ffa53be096c Mon Sep 17 00:00:00 2001 From: Elle Yoko Suzuki Date: Tue, 11 Dec 2012 00:15:39 -0800 Subject: [PATCH 2/3] asks for day of week, outputs day's shows only --- watchman.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/watchman.rb b/watchman.rb index 7f15cc1..351bcc2 100644 --- a/watchman.rb +++ b/watchman.rb @@ -19,3 +19,29 @@ Show.all.each do |show| puts show end + +puts +puts "What day are you interested in? (eg, Friday)" +answer = gets.chomp + +shows = [] +Show.all.each do |show| + if show.day_of_week == answer + shows << show + end +end + +if answer.empty? + puts 'No day was provided. No shows for you!' + exit +end + +puts "Shows for #{answer}:" + +if shows.size != 0 + shows.each do |s| + puts "#{s.name} at #{s.hour_of_day} on #{s.network}" + end +else + puts 'None' +end From c5da4ee7f7e78955b934e416667e7fb81055ff1c Mon Sep 17 00:00:00 2001 From: Elle Yoko Suzuki Date: Tue, 11 Dec 2012 01:38:12 -0800 Subject: [PATCH 3/3] new knitting related tables, show records with user input --- db/migrate/201212110018_create_projects.rb | 10 +++++++ db/migrate/201212110056_create_yarns.rb | 11 ++++++++ db/migrate/201212110059_create_needles.rb | 11 ++++++++ db/seed.rb | 19 +++++++++++++ models/needle.rb | 7 +++++ models/project.rb | 10 +++++++ models/yarn.rb | 7 +++++ watchman.rb | 31 ++++++++++++++++------ 8 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 db/migrate/201212110018_create_projects.rb create mode 100644 db/migrate/201212110056_create_yarns.rb create mode 100644 db/migrate/201212110059_create_needles.rb create mode 100644 models/needle.rb create mode 100644 models/project.rb create mode 100644 models/yarn.rb diff --git a/db/migrate/201212110018_create_projects.rb b/db/migrate/201212110018_create_projects.rb new file mode 100644 index 0000000..72beb6c --- /dev/null +++ b/db/migrate/201212110018_create_projects.rb @@ -0,0 +1,10 @@ +class CreateProjects < ActiveRecord::Migration + def change + create_table :projects do |t| + t.string :name + t.string :category + t.string :recipient + t.timestamps + end + end +end diff --git a/db/migrate/201212110056_create_yarns.rb b/db/migrate/201212110056_create_yarns.rb new file mode 100644 index 0000000..c44421e --- /dev/null +++ b/db/migrate/201212110056_create_yarns.rb @@ -0,0 +1,11 @@ +class CreateYarns < ActiveRecord::Migration + create_table :yarns do |t| + t.string :material + t.string :weight + t.timestamps + end + + change_table :projects do |t| + t.references :yarn + end +end diff --git a/db/migrate/201212110059_create_needles.rb b/db/migrate/201212110059_create_needles.rb new file mode 100644 index 0000000..ce3ecdd --- /dev/null +++ b/db/migrate/201212110059_create_needles.rb @@ -0,0 +1,11 @@ +class CreateNeedles < ActiveRecord::Migration + create_table :needles do |t| + t.string :category + t.string :size + t.timestamps + end + + change_table :projects do |t| + t.references :needle + end +end diff --git a/db/seed.rb b/db/seed.rb index f0b81ab..b5e543e 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,10 +1,29 @@ # Cleaning Out Network.delete_all Show.delete_all +Needle.delete_all +Yarn.delete_all +Project.delete_all + +# set up amc = Network.create(name: "AMC") nbc = Network.create(name: "NBC") cbs = Network.create(name: "CBS") + 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: 'Elementary', day_of_week: 'Thursday', hour_of_day: 22, network: cbs) Show.create(name: 'Person of Interest', day_of_week: 'Thursday', hour_of_day: 21, network: cbs) + +dpns3 = Needle.create(category: 'dpns', size: 3) +dpns2 = Needle.create(category: 'dpns', size: 2) +str8 = Needle.create(category: 'straights', size: 8) + +wool_worsted = Yarn.create(material: 'merino wool', weight: 'worsted') +acrylic_sock = Yarn.create(material: 'acrylic', weight: 'sock') + +Project.create(name: 'Birthday Present', category: 'socks', needle: dpns3, yarn: acrylic_sock, recipient: 'Yuki') +Project.create(name: 'Bro Graduation Present', category: 'hat', needle: str8, yarn: wool_worsted, recipient: 'Patrick') +Project.create(name: 'Bro New Year Present', category: 'scarf', needle: str8, yarn: wool_worsted, recipient: 'Chris') +Project.create(name: 'Practice Project', category: 'socks', needle: dpns2, yarn: acrylic_sock, recipient: 'self') +Project.create(name: 'Just Because', category: 'scarf', needle: str8, yarn: wool_worsted, recipient: 'Darryl') diff --git a/models/needle.rb b/models/needle.rb new file mode 100644 index 0000000..25b8d08 --- /dev/null +++ b/models/needle.rb @@ -0,0 +1,7 @@ +class Needle < ActiveRecord::Base + has_many :projects + + def to_s + "#{size} #{category}" + end +end diff --git a/models/project.rb b/models/project.rb new file mode 100644 index 0000000..829af71 --- /dev/null +++ b/models/project.rb @@ -0,0 +1,10 @@ +class Project < ActiveRecord::Base + validates_presence_of :name + + belongs_to :yarn + belongs_to :needle + + def to_s + "\"#{name}\", [#{category}, #{recipient}, #{needle}, #{yarn}]" + end +end diff --git a/models/yarn.rb b/models/yarn.rb new file mode 100644 index 0000000..03c86dd --- /dev/null +++ b/models/yarn.rb @@ -0,0 +1,7 @@ +class Yarn < ActiveRecord::Base + has_many :projects + + def to_s + "#{weight} #{material}" + end +end diff --git a/watchman.rb b/watchman.rb index 351bcc2..97711b7 100644 --- a/watchman.rb +++ b/watchman.rb @@ -31,17 +31,32 @@ end end -if answer.empty? - puts 'No day was provided. No shows for you!' - exit -end - -puts "Shows for #{answer}:" - if shows.size != 0 shows.each do |s| puts "#{s.name} at #{s.hour_of_day} on #{s.network}" end else - puts 'None' + puts 'No shows found.' end + +# output all my knitting projects +puts +puts "My current knitting projects: " +Project.all.each do |project| + puts project +end + +puts +puts "Which project would you like to see details for?" +answer = gets.chomp + +counter = 0 +Project.all.each do |proj| + if proj.name == answer + counter += 1 + puts proj + break + end +end + +puts 'Sorry, project not found.' if counter == 0