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 +1 -1
- data/lib/cal.rb +1 -1
- data/lib/cal/{ender.rb → monthly_calendar.rb} +6 -11
- data/lib/cal/version.rb +1 -1
- data/spec/cal/day_spec.rb +1 -0
- data/spec/cal/month_spec.rb +8 -9
- data/spec/cal/{ender_spec.rb → monthly_calendar_spec.rb} +19 -34
- metadata +5 -5
data/README.md
CHANGED
data/lib/cal.rb
CHANGED
@@ -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
|
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 :
|
12
|
+
attr_reader :date
|
20
13
|
|
21
14
|
def ==(other)
|
22
|
-
other.is_a?(
|
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
|
data/lib/cal/version.rb
CHANGED
data/spec/cal/day_spec.rb
CHANGED
data/spec/cal/month_spec.rb
CHANGED
@@ -4,21 +4,19 @@ describe Cal::Month do
|
|
4
4
|
|
5
5
|
subject { described_class.new @calendar }
|
6
6
|
|
7
|
-
before
|
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
|
13
|
-
subject
|
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
|
17
|
-
subject
|
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
|
21
|
-
subject
|
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::
|
4
|
-
subject { described_class.new @date, @options }
|
3
|
+
describe Cal::MonthlyCalendar do
|
5
4
|
|
6
|
-
|
7
|
-
@date = Date.new 2012, 2, 1
|
8
|
-
@options = {}
|
9
|
-
end
|
5
|
+
subject { described_class.new @date }
|
10
6
|
|
11
|
-
|
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
|
-
|
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
|
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
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
55
|
-
|
56
|
-
|
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
|
61
|
-
subject
|
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.
|
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-
|
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
|