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/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 3c028ff..b5e543e 100644 --- a/db/seed.rb +++ b/db/seed.rb @@ -1,7 +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 ebe9be4..97711b7 100644 --- a/watchman.rb +++ b/watchman.rb @@ -7,9 +7,56 @@ 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 + +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 shows.size != 0 + shows.each do |s| + puts "#{s.name} at #{s.hour_of_day} on #{s.network}" + end +else + 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