cal 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +10 -5
- data/lib/cal.rb +0 -1
- data/lib/cal/month.rb +30 -7
- data/lib/cal/monthly_calendar.rb +47 -14
- data/lib/cal/version.rb +1 -1
- data/spec/cal/month_spec.rb +101 -13
- data/spec/cal/monthly_calendar_spec.rb +152 -114
- metadata +2 -5
- data/lib/cal/year.rb +0 -19
- data/spec/cal/year_spec.rb +0 -34
data/README.md
CHANGED
@@ -20,21 +20,26 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
Cal is a simple calendar structure. It **does not** render a calendar. It **does not** handle events.
|
24
|
+
|
23
25
|
See the Rails app [https://github.com/austinthecoder/cal-app](https://github.com/austinthecoder/cal-app) for an example.
|
24
26
|
|
25
27
|
### Rails example
|
26
28
|
|
27
29
|
``` ruby
|
28
|
-
#
|
29
|
-
|
30
|
+
# routes
|
31
|
+
match 'calendar/:month', :to => 'calendars#show'
|
32
|
+
|
33
|
+
# controller
|
34
|
+
calendar = Cal::MonthlyCalendar.from_param params[:month], :start_week_on => :monday
|
30
35
|
|
31
|
-
#
|
36
|
+
# view
|
32
37
|
%h3
|
33
|
-
= link_to 'Previous month',
|
38
|
+
= link_to 'Previous month', calendar_path(calendar.previous)
|
34
39
|
|
|
35
40
|
= "#{calendar.month} #{calendar.year}"
|
36
41
|
|
|
37
|
-
= link_to 'Next month',
|
42
|
+
= link_to 'Next month', calendar_path(calendar.next)
|
38
43
|
|
39
44
|
%table
|
40
45
|
%thead
|
data/lib/cal.rb
CHANGED
data/lib/cal/month.rb
CHANGED
@@ -1,18 +1,41 @@
|
|
1
1
|
module Cal
|
2
2
|
class Month
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
def initialize(year, number)
|
7
|
+
@year = year.to_i
|
8
|
+
@number = number.to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :year, :number
|
12
|
+
|
13
|
+
alias_method :to_i, :number
|
14
|
+
|
15
|
+
def <=>(other)
|
16
|
+
date <=> other.send(:date) if other.is_a?(self.class)
|
6
17
|
end
|
7
18
|
|
8
|
-
|
19
|
+
def to_s(*args)
|
20
|
+
date.strftime *args
|
21
|
+
end
|
9
22
|
|
10
|
-
def
|
11
|
-
|
23
|
+
def succ
|
24
|
+
self.class.new *(number == 12 ? [(year + 1), 1] : [year, (number + 1)])
|
12
25
|
end
|
13
26
|
|
14
|
-
def
|
15
|
-
|
27
|
+
def previous
|
28
|
+
self.class.new *(number == 1 ? [(year - 1), 12] : [year, (number - 1)])
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_month
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def date
|
38
|
+
@date ||= Date.new year, number
|
16
39
|
end
|
17
40
|
|
18
41
|
end
|
data/lib/cal/monthly_calendar.rb
CHANGED
@@ -4,6 +4,8 @@ require 'active_support/core_ext/string/conversions'
|
|
4
4
|
module Cal
|
5
5
|
class MonthlyCalendar
|
6
6
|
|
7
|
+
include Comparable
|
8
|
+
|
7
9
|
DAY_NAMES = {
|
8
10
|
:sunday => 0,
|
9
11
|
:monday => 1,
|
@@ -14,27 +16,50 @@ module Cal
|
|
14
16
|
:saturday => 6
|
15
17
|
}
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
+
class << self
|
20
|
+
def from_month(month, options = {})
|
21
|
+
month = month.to_month
|
22
|
+
new month.year, month.number, options
|
23
|
+
end
|
24
|
+
|
25
|
+
def from_param(param)
|
26
|
+
year, month_number = if param.present?
|
27
|
+
param.split '-'
|
28
|
+
else
|
29
|
+
now = Date.current
|
30
|
+
[now.year, now.month]
|
31
|
+
end
|
32
|
+
new year, month_number
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(year, month_number, options = {})
|
19
37
|
@start_week_on = options[:start_week_on] || :sunday
|
20
|
-
@month = Month.new
|
21
|
-
@year = Year.new self
|
38
|
+
@month = Month.new year, month_number
|
22
39
|
end
|
23
40
|
|
24
|
-
attr_reader :
|
41
|
+
attr_reader :month
|
42
|
+
|
43
|
+
delegate :year, :to => :month
|
25
44
|
|
26
|
-
def
|
27
|
-
other.is_a?(MonthlyCalendar) &&
|
28
|
-
|
29
|
-
|
45
|
+
def <=>(other)
|
46
|
+
if other.is_a?(MonthlyCalendar) && start_week_on == other.send(:start_week_on)
|
47
|
+
month <=> other.month
|
48
|
+
end
|
30
49
|
end
|
31
50
|
|
32
51
|
def first_day
|
33
|
-
@first_day ||=
|
52
|
+
@first_day ||= begin
|
53
|
+
date = Date.new(year, month.to_i).beginning_of_month.beginning_of_week(start_week_on)
|
54
|
+
Day.new date, self
|
55
|
+
end
|
34
56
|
end
|
35
57
|
|
36
58
|
def last_day
|
37
|
-
@last_day ||=
|
59
|
+
@last_day ||= begin
|
60
|
+
date = Date.new(year, month.to_i).end_of_month.end_of_week(start_week_on)
|
61
|
+
Day.new date, self
|
62
|
+
end
|
38
63
|
end
|
39
64
|
|
40
65
|
def days
|
@@ -46,16 +71,24 @@ module Cal
|
|
46
71
|
end
|
47
72
|
|
48
73
|
def previous
|
49
|
-
self.class.
|
74
|
+
self.class.from_month month.previous, :start_week_on => start_week_on
|
50
75
|
end
|
51
76
|
|
52
77
|
def next
|
53
|
-
self.class.
|
78
|
+
self.class.from_month month.succ, :start_week_on => start_week_on
|
54
79
|
end
|
55
80
|
|
56
81
|
def day_names
|
57
|
-
%w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday].rotate DAY_NAMES[
|
82
|
+
%w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday].rotate DAY_NAMES[start_week_on]
|
58
83
|
end
|
59
84
|
|
85
|
+
def to_param
|
86
|
+
"#{year}-#{month.to_i}"
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
attr_reader :start_week_on
|
92
|
+
|
60
93
|
end
|
61
94
|
end
|
data/lib/cal/version.rb
CHANGED
data/spec/cal/month_spec.rb
CHANGED
@@ -2,33 +2,121 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cal::Month do
|
4
4
|
|
5
|
-
subject { described_class.new @
|
5
|
+
subject { described_class.new @year, @month_number }
|
6
6
|
|
7
|
-
before
|
7
|
+
before do
|
8
|
+
@year = 2012
|
9
|
+
@month_number = 3
|
10
|
+
end
|
8
11
|
|
9
|
-
describe "
|
10
|
-
it "
|
11
|
-
|
12
|
+
describe "initialize" do
|
13
|
+
it "coerces the year and month number to integers" do
|
14
|
+
@year = "2012"
|
15
|
+
@month_number = "04"
|
16
|
+
subject.year.should == 2012
|
17
|
+
subject.number.should == 4
|
12
18
|
end
|
19
|
+
end
|
20
|
+
|
21
|
+
it { should be_a(Comparable) }
|
13
22
|
|
14
|
-
|
15
|
-
|
23
|
+
describe "<=>" do
|
24
|
+
it "is nil with a non month" do
|
25
|
+
(subject <=> Object.new).should be_nil
|
16
26
|
end
|
17
27
|
|
28
|
+
context "given another month" do
|
29
|
+
before { @other = described_class.new @year, @month_number }
|
30
|
+
|
31
|
+
context "when the other's year is the same" do
|
32
|
+
it "is 0 when the other's month is the same" do
|
33
|
+
(subject <=> @other).should == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
it "is -1 when the other's month is higher" do
|
37
|
+
@month_number = 2
|
38
|
+
(subject <=> @other).should == -1
|
39
|
+
end
|
40
|
+
|
41
|
+
it "is 1 when the other's month is lower" do
|
42
|
+
@month_number = 4
|
43
|
+
(subject <=> @other).should == 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it "is -1 when the other's year is higher" do
|
48
|
+
@year = 2011
|
49
|
+
(subject <=> @other).should == -1
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is 1 when the other's year is lower" do
|
53
|
+
@year = 2013
|
54
|
+
(subject <=> @other).should == 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "==" do
|
18
60
|
it "is false with a non month" do
|
19
61
|
(subject == Object.new).should be_false
|
20
62
|
end
|
21
|
-
end
|
22
63
|
|
23
|
-
|
24
|
-
|
25
|
-
|
64
|
+
context "given another month" do
|
65
|
+
before { @month = described_class.new @year, @month_number }
|
66
|
+
|
67
|
+
it "is true if the comparison is zero" do
|
68
|
+
subject.stub(:<=>) { 0 }
|
69
|
+
(subject == @month).should be_true
|
70
|
+
end
|
71
|
+
|
72
|
+
it "is false if the comparison is not zero" do
|
73
|
+
subject.stub(:<=>) { -1 }
|
74
|
+
(subject == @month).should be_false
|
75
|
+
end
|
26
76
|
end
|
27
77
|
end
|
28
78
|
|
79
|
+
it { subject.number.should == @month_number }
|
80
|
+
|
29
81
|
describe "to_s" do
|
30
|
-
|
31
|
-
|
82
|
+
it "is the result of formatting a date object" do
|
83
|
+
date = Object.new
|
84
|
+
format = Object.new
|
85
|
+
result = Object.new
|
86
|
+
Date.stub(:new) { |*args| date if args == [@year, @month_number] }
|
87
|
+
date.stub(:strftime) { |f| result if f == format }
|
88
|
+
subject.to_s(format).should == result
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "year" do
|
93
|
+
it "is the given year" do
|
94
|
+
subject.year.should == 2012
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "succ" do
|
99
|
+
[[2012, 12, 2013, 1], [2012, 1, 2012, 2]].each do |year, month_number, new_year, new_month_number|
|
100
|
+
it "is the next month" do
|
101
|
+
@year = year
|
102
|
+
@month_number = month_number
|
103
|
+
subject.succ.should == described_class.new(new_year, new_month_number)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "previous" do
|
109
|
+
[[2012, 12, 2012, 11], [2012, 1, 2011, 12]].each do |year, month_number, new_year, new_month_number|
|
110
|
+
it "is the previous month" do
|
111
|
+
@year = year
|
112
|
+
@month_number = month_number
|
113
|
+
subject.previous.should == described_class.new(new_year, new_month_number)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "to_month" do
|
119
|
+
it { subject.to_month.should == subject }
|
32
120
|
end
|
33
121
|
|
34
122
|
end
|
@@ -2,160 +2,198 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Cal::MonthlyCalendar do
|
4
4
|
|
5
|
-
|
5
|
+
describe "class methods" do
|
6
|
+
subject { described_class }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
describe "from_month" do
|
9
|
+
it "returns a calendar for the month's year and month number" do
|
10
|
+
subject.from_month(Cal::Month.new(2012, 11)).should == subject.new(2012, 11)
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
it "raises an error without something that can be converted to a month" do
|
14
|
+
[nil, Object.new].each do |object|
|
15
|
+
expect { subject.from_month(object) }.to raise_error(NoMethodError)
|
16
|
+
end
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
describe "from_param" do
|
21
|
+
it "is the calendar for the given param" do
|
22
|
+
calendar = subject.new 2012, 5
|
23
|
+
subject.from_param(calendar.to_param).should == calendar
|
22
24
|
end
|
23
|
-
end
|
24
|
-
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
context "with a blank param" do
|
27
|
+
it "returns a calendar for the current year and month" do
|
28
|
+
[' ', nil].each do |param|
|
29
|
+
date = Date.current
|
30
|
+
subject.from_param(param).should == subject.new(date.year, date.month)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
|
-
describe "
|
33
|
-
|
34
|
-
calendar = described_class.new Date.new(@date.year, @date.month, (@date.day + 1))
|
35
|
-
(subject == calendar).should be_true
|
36
|
-
end
|
37
|
+
describe "instance methods" do
|
38
|
+
subject { described_class.new @year, @month, @options }
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
before do
|
41
|
+
@year = 2012
|
42
|
+
@month = 2
|
43
|
+
@options = {}
|
41
44
|
end
|
42
45
|
|
43
|
-
it
|
44
|
-
calendar = described_class.new Date.new((@date.year + 1), @date.month, @date.day)
|
45
|
-
(subject == calendar).should be_false
|
46
|
-
end
|
46
|
+
it { should be_a(Comparable) }
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
describe "initialize" do
|
49
|
+
it "coerces the year and month number to integers" do
|
50
|
+
@year = "2012"
|
51
|
+
@month = "04"
|
52
|
+
subject.should == described_class.new(2012, 4)
|
53
|
+
end
|
50
54
|
end
|
51
|
-
end
|
52
55
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
+
describe "<=>" do
|
57
|
+
it "is nil with a non monthly calendar" do
|
58
|
+
(subject <=> Object.new).should be_nil
|
59
|
+
end
|
56
60
|
|
57
|
-
|
58
|
-
|
59
|
-
|
61
|
+
it "is nil with a non monthly calendar" do
|
62
|
+
(subject <=> Object.new).should be_nil
|
63
|
+
end
|
64
|
+
|
65
|
+
context "given another monthly calendar" do
|
66
|
+
before { @other = described_class.new @year, @month, @options }
|
60
67
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
[:saturday, [1, 28]]
|
71
|
-
].each do |weekday, month_day|
|
72
|
-
context "when the weekday is set to start on #{weekday}" do
|
73
|
-
before { @options[:start_week_on] = weekday }
|
74
|
-
it "is the first viewable day on the calendar" do
|
75
|
-
subject.first_day.should == Cal::Day.new(Date.new(2012, *month_day), subject)
|
68
|
+
it "is nil when the other's start day is different" do
|
69
|
+
@options[:start_week_on] = :tuesday
|
70
|
+
(subject <=> @other).should be_nil
|
71
|
+
end
|
72
|
+
|
73
|
+
it "is the result of comparing the months when the other's start day is the same" do
|
74
|
+
result = Object.new
|
75
|
+
subject.month.stub(:<=>) { |m| result if m == @other.month }
|
76
|
+
(subject <=> @other).should == result
|
76
77
|
end
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
|
81
|
-
subject.
|
81
|
+
describe "month" do
|
82
|
+
it { subject.month.should == Cal::Month.new(@year, @month) }
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "year" do
|
86
|
+
it { subject.year.should == @year }
|
82
87
|
end
|
83
|
-
end
|
84
88
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
89
|
+
describe "first_day" do
|
90
|
+
before { @year, @month = 2012, 2 }
|
91
|
+
|
92
|
+
[
|
93
|
+
[:monday, [1, 30]],
|
94
|
+
[:tuesday, [1, 31]],
|
95
|
+
[:wednesday, [2, 1]],
|
96
|
+
[:thursday, [1, 26]],
|
97
|
+
[:friday, [1, 27]],
|
98
|
+
[:saturday, [1, 28]]
|
99
|
+
].each do |weekday, month_day|
|
100
|
+
context "when the weekday is set to start on #{weekday}" do
|
101
|
+
before { @options[:start_week_on] = weekday }
|
102
|
+
it "is the first viewable day on the calendar" do
|
103
|
+
subject.first_day.should == Cal::Day.new(Date.new(2012, *month_day), subject)
|
104
|
+
end
|
100
105
|
end
|
101
106
|
end
|
107
|
+
|
108
|
+
it "is the first viewable day on the calendar, using sunday as the default start day" do
|
109
|
+
subject.first_day.should == Cal::Day.new(Date.new(2012, 1, 29), subject)
|
110
|
+
end
|
102
111
|
end
|
103
112
|
|
104
|
-
|
105
|
-
|
113
|
+
describe "last_day" do
|
114
|
+
before { @year, @month = 2012, 2 }
|
115
|
+
|
116
|
+
[
|
117
|
+
[:monday, [3, 4]],
|
118
|
+
[:tuesday, [3, 5]],
|
119
|
+
[:wednesday, [3, 6]],
|
120
|
+
[:thursday, [2, 29]],
|
121
|
+
[:friday, [3, 1]],
|
122
|
+
[:saturday, [3, 2]]
|
123
|
+
].each do |weekday, month_day|
|
124
|
+
context "when the weekday is set to start on #{weekday}" do
|
125
|
+
before { @options[:start_week_on] = weekday }
|
126
|
+
it "is the last viewable day on the calendar" do
|
127
|
+
subject.last_day.should == Cal::Day.new(Date.new(2012, *month_day), subject)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
it "is the last viewable day on the calendar, using sunday as the default start day" do
|
133
|
+
subject.last_day.should == Cal::Day.new(Date.new(2012, 3, 3), subject)
|
134
|
+
end
|
106
135
|
end
|
107
|
-
end
|
108
136
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
137
|
+
describe "days" do
|
138
|
+
it "is a range of the first day to the last day" do
|
139
|
+
@year, @month = 2012, 2
|
140
|
+
first_day = Cal::Day.new Date.new(2012, 1, 29), subject
|
141
|
+
last_day = Cal::Day.new Date.new(2012, 3, 3), subject
|
142
|
+
subject.days.should == (first_day..last_day)
|
143
|
+
end
|
115
144
|
end
|
116
|
-
end
|
117
145
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
146
|
+
describe "weeks" do
|
147
|
+
it "an array of the days in groups of 7" do
|
148
|
+
@year, @month = 2012, 2
|
149
|
+
subject.weeks.should == [
|
150
|
+
%w[01-29 01-30 01-31 02-01 02-02 02-03 02-04].map { |s| Cal::Day.new Date.parse("2012-#{s}"), subject },
|
151
|
+
%w[02-05 02-06 02-07 02-08 02-09 02-10 02-11].map { |s| Cal::Day.new Date.parse("2012-#{s}"), subject },
|
152
|
+
%w[02-12 02-13 02-14 02-15 02-16 02-17 02-18].map { |s| Cal::Day.new Date.parse("2012-#{s}"), subject },
|
153
|
+
%w[02-19 02-20 02-21 02-22 02-23 02-24 02-25].map { |s| Cal::Day.new Date.parse("2012-#{s}"), subject },
|
154
|
+
%w[02-26 02-27 02-28 02-29 03-01 03-02 03-03].map { |s| Cal::Day.new Date.parse("2012-#{s}"), subject }
|
155
|
+
]
|
156
|
+
end
|
128
157
|
end
|
129
|
-
end
|
130
158
|
|
131
|
-
|
132
|
-
|
133
|
-
|
159
|
+
describe "previous" do
|
160
|
+
it "returns the calendar for the previous month" do
|
161
|
+
@options[:start_week_on] = :wednesday
|
162
|
+
subject.previous.should == described_class.new(@year, (@month - 1), @options)
|
163
|
+
end
|
134
164
|
end
|
135
|
-
end
|
136
165
|
|
137
|
-
|
138
|
-
|
139
|
-
|
166
|
+
describe "next" do
|
167
|
+
it "returns the calendar for the next month" do
|
168
|
+
@options[:start_week_on] = :wednesday
|
169
|
+
subject.next.should == described_class.new(@year, (@month + 1), @options)
|
170
|
+
end
|
140
171
|
end
|
141
|
-
end
|
142
172
|
|
143
|
-
|
144
|
-
|
145
|
-
|
173
|
+
describe "day_names" do
|
174
|
+
it "defaults to sunday through saturday" do
|
175
|
+
subject.day_names.should == %w[Sunday Monday Tuesday Wednesday Thursday Friday Saturday]
|
176
|
+
end
|
177
|
+
|
178
|
+
[
|
179
|
+
%w[Monday Tuesday Wednesday Thursday Friday Saturday Sunday],
|
180
|
+
%w[Tuesday Wednesday Thursday Friday Saturday Sunday Monday],
|
181
|
+
%w[Wednesday Thursday Friday Saturday Sunday Monday Tuesday],
|
182
|
+
%w[Thursday Friday Saturday Sunday Monday Tuesday Wednesday],
|
183
|
+
%w[Friday Saturday Sunday Monday Tuesday Wednesday Thursday],
|
184
|
+
%w[Saturday Sunday Monday Tuesday Wednesday Thursday Friday]
|
185
|
+
].each do |day_names|
|
186
|
+
it "is #{day_names[0]} through #{day_names[6]} when the weekday is set to start on #{day_names[0]}" do
|
187
|
+
@options[:start_week_on] = day_names[0].downcase.to_sym
|
188
|
+
subject.day_names.should == day_names
|
189
|
+
end
|
190
|
+
end
|
146
191
|
end
|
147
192
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
%w[Thursday Friday Saturday Sunday Monday Tuesday Wednesday],
|
153
|
-
%w[Friday Saturday Sunday Monday Tuesday Wednesday Thursday],
|
154
|
-
%w[Saturday Sunday Monday Tuesday Wednesday Thursday Friday]
|
155
|
-
].each do |day_names|
|
156
|
-
it "is #{day_names[0]} through #{day_names[6]} when the weekday is set to start on #{day_names[0]}" do
|
157
|
-
@options[:start_week_on] = day_names[0].downcase.to_sym
|
158
|
-
subject.day_names.should == day_names
|
193
|
+
describe "to_param" do
|
194
|
+
it "is the year and month string" do
|
195
|
+
@year, @month = 2012, 12
|
196
|
+
subject.to_param.should == "2012-12"
|
159
197
|
end
|
160
198
|
end
|
161
199
|
end
|
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.5.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-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -62,11 +62,9 @@ files:
|
|
62
62
|
- lib/cal/month.rb
|
63
63
|
- lib/cal/monthly_calendar.rb
|
64
64
|
- lib/cal/version.rb
|
65
|
-
- lib/cal/year.rb
|
66
65
|
- spec/cal/day_spec.rb
|
67
66
|
- spec/cal/month_spec.rb
|
68
67
|
- spec/cal/monthly_calendar_spec.rb
|
69
|
-
- spec/cal/year_spec.rb
|
70
68
|
- spec/spec_helper.rb
|
71
69
|
homepage: https://github.com/austinthecoder/cal
|
72
70
|
licenses: []
|
@@ -96,5 +94,4 @@ test_files:
|
|
96
94
|
- spec/cal/day_spec.rb
|
97
95
|
- spec/cal/month_spec.rb
|
98
96
|
- spec/cal/monthly_calendar_spec.rb
|
99
|
-
- spec/cal/year_spec.rb
|
100
97
|
- spec/spec_helper.rb
|
data/lib/cal/year.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Cal
|
2
|
-
class Year
|
3
|
-
|
4
|
-
def initialize(calendar)
|
5
|
-
@calendar = calendar
|
6
|
-
end
|
7
|
-
|
8
|
-
attr_reader :calendar
|
9
|
-
|
10
|
-
def ==(other)
|
11
|
-
other.is_a?(Year) && other.calendar == calendar
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
calendar.date.strftime "%Y"
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
data/spec/cal/year_spec.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Cal::Year do
|
4
|
-
|
5
|
-
subject { described_class.new @calendar }
|
6
|
-
|
7
|
-
before { @calendar = OpenStruct.new }
|
8
|
-
|
9
|
-
describe "==" do
|
10
|
-
it "is true with another year with the same calendar" do
|
11
|
-
(subject == described_class.new(@calendar)).should be_true
|
12
|
-
end
|
13
|
-
|
14
|
-
it "is false with another year with a different calendar" do
|
15
|
-
(subject == described_class.new(Object.new)).should be_false
|
16
|
-
end
|
17
|
-
|
18
|
-
it "is false with a non year" do
|
19
|
-
(subject == Object.new).should be_false
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "calendar" do
|
24
|
-
it "is the given calendar" do
|
25
|
-
subject.calendar.should == @calendar
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "to_s" do
|
30
|
-
before { @calendar.date = Date.new 1983 }
|
31
|
-
it { subject.to_s.should == '1983' }
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|