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

eagle-, tiger-, + panda-level tasks #15

Open
wants to merge 3 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/201212110018_create_projects.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions db/migrate/201212110056_create_yarns.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions db/migrate/201212110059_create_needles.rb
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -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')
7 changes: 7 additions & 0 deletions models/needle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Needle < ActiveRecord::Base
has_many :projects

def to_s
"#{size} #{category}"
end
end
10 changes: 10 additions & 0 deletions models/project.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions models/yarn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Yarn < ActiveRecord::Base
has_many :projects

def to_s
"#{weight} #{material}"
end
end
57 changes: 52 additions & 5 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'd rather just delete commented code)

#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|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you should use the ActiveRecord query interface...

shows = Show.where(day_of_week: answer)

if shows.blank?
  shows.each do |s|
    puts "#{s.name} at #{s.hour_of_day} on #{s.network}"
  end
else
  puts 'No shows found'
end

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