Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 0 additions & 6 deletions config/database.yml.sample

This file was deleted.

4 changes: 2 additions & 2 deletions db/migrate/201205031230_create_shows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class CreateShows < ActiveRecord::Migration
def change
create_table :shows do |t|
t.string :name
t.string :day_of_week
t.string :day_of_week
t.integer :hour_of_day
end
end
end
end
13 changes: 0 additions & 13 deletions db/migrate/201205031300_create_networks.rb

This file was deleted.

8 changes: 6 additions & 2 deletions db/seed.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Cleaning Out

Network.delete_all
Show.delete_all
amc = Network.create(name: "AMC")
nbc = Network.create(name: "NBC")
netflix = Network.create(name: "Netflix")
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: "Community", day_of_week: "Thursday", hour_of_day: 19, network: nbc)
Show.create(name: "House of Cards", day_of_week: "Thursday", hour_of_day: 0, network: netflix)
Show.create(name: "Orange is the New Black", day_of_week: "Sunday" , hour_of_day: 0, network: netflix)

Copy link
Member

Choose a reason for hiding this comment

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

👍 on the shows, BTW. I ❤️ them 😃

12 changes: 7 additions & 5 deletions db/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
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

# Setup out connection_details
ActiveRecord::Base.establish_connection(connection_details.merge({database: 'postgres', schema_search_path: 'public'}))
# create the 'tv' database
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/")

3 changes: 2 additions & 1 deletion models/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class Network < ActiveRecord::Base

def to_s
name
end
end
end

13 changes: 7 additions & 6 deletions models/show.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
class Show < ActiveRecord::Base
belongs_to :network
class Show < ActiveRecord::Base
belongs_to :network

validates_presence_of :name
#validates_presence_of :name
Copy link
Member

Choose a reason for hiding this comment

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

I don't like code that is commented... I recommend removing it, since you can always go back in time via git.

def to_s
"#{name}, #{day_of_week}, #{hour_of_day}, #{network}"
end
Copy link
Member

Choose a reason for hiding this comment

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

Is that formatting local to your culture? 05:Wed:00 on NBC?

Or, did "day_of_week" sneek in there instead of minute?


def to_s
"#{name} airs at #{hour_of_day}:#{day_of_week}:00 on #{network} "
end
end

Empty file removed spec/.gitkeep
Empty file.
24 changes: 22 additions & 2 deletions watchman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@
require "./db/setup"
Dir.glob('./models/*').each { |r| require r}
require "./db/seed"
require "./db/seeds"
Copy link
Member

Choose a reason for hiding this comment

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

I can't figure this one out --- the db/seeds... is that a local file you have?



puts "There are #{Show.count} in the database"

Network.all.each do |network|
puts "Shows airing on #{network}"
network.shows.each do |show|
network.shows.each do |show| #this is really cool
puts show
end
end
end
puts "------------------------"
Show.all.each do |show|
puts show
end
puts "------------------------"
puts "Which day do you want to watch the show?"
day = gets.chomp().capitalize
puts "Shows airing on #{day}"
Show.all.each do |show|
puts show if show.day_of_week == day
Copy link
Member

Choose a reason for hiding this comment

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

This works well... I also like this method, where we limit the things we are looping before we loop over them

Show.all.to_a.select{|show| show.day_of_week == day}.each do |show|
  puts show
end

So the select will only return items that match the day_of_week == day for each item in the array.

end

puts "-------------------------"


Food.all.each do |food|
puts food
end