Skip to content
Browse files

determine the current week of the season.

  • Loading branch information...
1 parent c96b0a4 commit e1ee5709c4911ee6dd6e6a7128f077463a1fcf64 @cjolly committed Dec 8, 2012
Showing with 31 additions and 6 deletions.
  1. +10 −1 lib/pickem.rb
  2. +21 −5 spec/pickem_spec.rb
View
11 lib/pickem.rb
@@ -3,17 +3,26 @@
require 'pickem/scrapers/cbs_sports'
require 'terminal-table'
+require 'date'
module Pickem
+ FIRST_WEEK_OF_SEASON = 36
+
def self.results
scraper = Scrapers::CBSSports.scrape!
table = Terminal::Table.new({
- title: scraper.source,
+ title: "Week #{current_week}\n#{scraper.source}",
headings: ['Away', 'Home', 'Current Line'],
rows: scraper.picks
})
table.align_column(2, :right)
table
end
+
+ def self.current_week(today = Date.today)
+ week = today.cweek - FIRST_WEEK_OF_SEASON
+ week += 1 unless today.monday?
+ week
+ end
end
View
26 spec/pickem_spec.rb
@@ -1,9 +1,25 @@
require 'spec_helper'
-describe Pickem, vcr: {cassette_name: "cbs_sports"} do
- it "returns a table of results" do
- table = Pickem.results
- table.should be_a(Terminal::Table)
- table.rows.size.should == 16
+describe Pickem do
+ context ".results", vcr: {cassette_name: "cbs_sports"} do
+ it "returns a table of results" do
+ table = Pickem.results
+ table.should be_a(Terminal::Table)
+ table.rows.size.should == 16
+ end
+ end
+
+ context ".week" do
+ it "knows the week of the season" do
+ Pickem.current_week(Date.new(2012, 12, 8)).should == 14
+ end
+
+ it "should still consider monday the preceeding week of the season" do
+ Pickem.current_week(Date.new(2012, 12, 10)).should == 14
+ end
+
+ it "tuesday becomes first day of the next week" do
+ Pickem.current_week(Date.new(2012, 12, 11)).should == 15
+ end
end
end

0 comments on commit e1ee570

Please sign in to comment.
Something went wrong with that request. Please try again.