cal 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
24
24
 
25
25
  ``` ruby
26
26
  # in the controller
27
- - calendar = Cal::Ender.new params[:date]
27
+ - calendar = Cal::MonthlyCalendar.new params[:date]
28
28
 
29
29
  # in the view
30
30
  %h3
data/lib/cal.rb CHANGED
@@ -2,7 +2,7 @@ require "cal/version"
2
2
 
3
3
  module Cal
4
4
 
5
- autoload :Ender, 'cal/ender'
5
+ autoload :MonthlyCalendar, 'cal/monthly_calendar'
6
6
  autoload :Day, 'cal/day'
7
7
  autoload :Month, 'cal/month'
8
8
 
@@ -3,23 +3,18 @@ require 'active_support/core_ext/array/grouping'
3
3
  require 'active_support/core_ext/string/conversions'
4
4
 
5
5
  module Cal
6
- class Ender
7
-
8
- def initialize(dateable, options = {})
9
- options = {:format => :monthly}.merge options
10
-
11
- if options[:format] != :monthly
12
- raise ArgumentError, "only supported format currently is :monthly"
13
- end
6
+ class MonthlyCalendar
14
7
 
8
+ def initialize(dateable)
15
9
  @date = dateable.to_date
16
- @format = options[:format]
17
10
  end
18
11
 
19
- attr_reader :format, :date
12
+ attr_reader :date
20
13
 
21
14
  def ==(other)
22
- other.is_a?(Ender) && other.date == date
15
+ other.is_a?(MonthlyCalendar) &&
16
+ other.date.year == date.year &&
17
+ other.date.month == date.month
23
18
  end
24
19
 
25
20
  def month
@@ -1,5 +1,5 @@
1
1
  module Cal
2
2
 
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
 
5
5
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cal::Day do
4
+
4
5
  subject { described_class.new @date, @calendar }
5
6
 
6
7
  before do
@@ -4,21 +4,19 @@ describe Cal::Month do
4
4
 
5
5
  subject { described_class.new @calendar }
6
6
 
7
- before do
8
- @calendar = OpenStruct.new :date => Date.new(2012, 3, 13)
9
- end
7
+ before { @calendar = OpenStruct.new }
10
8
 
11
9
  describe "==" do
12
- it "is true with a Cal::Month with the same calendar" do
13
- subject.should == described_class.new(@calendar)
10
+ it "is true with another month with the same calendar" do
11
+ (subject == described_class.new(@calendar)).should be_true
14
12
  end
15
13
 
16
- it "is false with a Cal::Month with a different calendar" do
17
- subject.should_not == described_class.new(Object.new)
14
+ it "is false with another month with a different calendar" do
15
+ (subject == described_class.new(Object.new)).should be_false
18
16
  end
19
17
 
20
- it "is false with a non-Cal::Month" do
21
- subject.should_not == Object.new
18
+ it "is false with a non month" do
19
+ (subject == Object.new).should be_false
22
20
  end
23
21
  end
24
22
 
@@ -29,6 +27,7 @@ describe Cal::Month do
29
27
  end
30
28
 
31
29
  describe "to_s" do
30
+ before { @calendar.stub(:date) { Date.new 2012, 3 } }
32
31
  it { subject.to_s.should == 'March' }
33
32
  end
34
33
 
@@ -1,43 +1,25 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Cal::Ender do
4
- subject { described_class.new @date, @options }
3
+ describe Cal::MonthlyCalendar do
5
4
 
6
- before do
7
- @date = Date.new 2012, 2, 1
8
- @options = {}
9
- end
5
+ subject { described_class.new @date }
10
6
 
11
- describe "initialize" do
12
- it "raises argument error if given format isn't :monthly" do
13
- @options[:format] = :weekly
14
- expect { subject }.to raise_error(ArgumentError)
15
- end
7
+ before { @date = Date.new 2012, 2 }
16
8
 
17
- it "raises an error if the first arg can't be converted to a date" do
9
+ describe "initialize" do
10
+ it "raises an error if arg can't be converted to a date" do
18
11
  ['Octember', Object.new, '2012'].each do |obj|
19
12
  expect { described_class.new obj }.to raise_error
20
13
  end
21
14
  end
22
15
 
23
- it "doesn't raise an error if the first arg can be converted to a date" do
16
+ it "doesn't raise an error if arg can be converted to a date" do
24
17
  [Date.current, Date.new(2012, 1, 15), '2012-02-24'].each do |obj|
25
18
  expect { described_class.new obj }.to_not raise_error
26
19
  end
27
20
  end
28
21
  end
29
22
 
30
- describe "format" do
31
- it "defaults to monthly" do
32
- subject.format.should == :monthly
33
- end
34
-
35
- it "otherwise is the given format" do
36
- @options[:format] = :monthly
37
- subject.format.should == :monthly
38
- end
39
- end
40
-
41
23
  describe "date" do
42
24
  it "is the given date" do
43
25
  subject.date.should == @date
@@ -45,20 +27,23 @@ describe Cal::Ender do
45
27
  end
46
28
 
47
29
  describe "==" do
48
- it "is true with another calendar with the same format and date" do
49
- @date = Date.new 2012, 2, 1
50
- @options[:format] = :monthly
51
- subject.should == described_class.new(@date, @options)
30
+ it "is true with another monthly calendar in the same month and year" do
31
+ calendar = described_class.new Date.new(@date.year, @date.month, (@date.day + 1))
32
+ (subject == calendar).should be_true
33
+ end
34
+
35
+ it "is false with another monthly calendar with a different month" do
36
+ calendar = described_class.new Date.new(@date.year, (@date.month + 1), @date.day)
37
+ (subject == calendar).should be_false
52
38
  end
53
39
 
54
- it "is false with another calendar with a different date" do
55
- @date = Date.new 2012, 2, 1
56
- @options[:format] = :monthly
57
- subject.should_not == described_class.new(Date.new(2012, 2, 2), @options)
40
+ it "is false with another monthly calendar with a different year" do
41
+ calendar = described_class.new Date.new((@date.year + 1), @date.month, @date.day)
42
+ (subject == calendar).should be_false
58
43
  end
59
44
 
60
- it "is false with a non-Ender object" do
61
- subject.should_not == Object.new
45
+ it "is false with a non monthly calendar" do
46
+ (subject == Object.new).should be_false
62
47
  end
63
48
  end
64
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-06 00:00:00.000000000 Z
12
+ date: 2012-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -59,12 +59,12 @@ files:
59
59
  - cal.gemspec
60
60
  - lib/cal.rb
61
61
  - lib/cal/day.rb
62
- - lib/cal/ender.rb
63
62
  - lib/cal/month.rb
63
+ - lib/cal/monthly_calendar.rb
64
64
  - lib/cal/version.rb
65
65
  - spec/cal/day_spec.rb
66
- - spec/cal/ender_spec.rb
67
66
  - spec/cal/month_spec.rb
67
+ - spec/cal/monthly_calendar_spec.rb
68
68
  - spec/spec_helper.rb
69
69
  homepage: ''
70
70
  licenses: []
@@ -92,6 +92,6 @@ specification_version: 3
92
92
  summary: A low level calendar engine.
93
93
  test_files:
94
94
  - spec/cal/day_spec.rb
95
- - spec/cal/ender_spec.rb
96
95
  - spec/cal/month_spec.rb
96
+ - spec/cal/monthly_calendar_spec.rb
97
97
  - spec/spec_helper.rb