File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,21 @@ class Humanizer
1818 Saturday
1919 ] . freeze
2020
21+ MONTH_NAMES = %w[
22+ January
23+ February
24+ March
25+ April
26+ May
27+ June
28+ July
29+ August
30+ September
31+ October
32+ November
33+ December
34+ ] . freeze
35+
2136 def initialize ( rrule , options )
2237 @rrule = rrule
2338 @options = options
@@ -97,6 +112,17 @@ def daily
97112 end
98113 end
99114
115+ def yearly
116+ add interval_option if interval_option != 1
117+ add plural? ( interval_option ) ? 'years' : 'year'
118+
119+ add 'on' if bymonthday_option || bymonth_option
120+
121+ add list ( options . fetch ( :bymonth ) , method ( :monthtext ) , 'and' ) if bymonth_option
122+
123+ add list ( bymonthday_option . map { |o | nth ( o ) } ) , :to_s , 'and' if bymonthday_option
124+ end
125+
100126 def weekly
101127 if interval_option != 1
102128 add interval_option
@@ -157,6 +183,10 @@ def weekdaytext(day)
157183 [ day . ordinal && nth ( day . ordinal ) , DAY_NAMES [ day . index ] ] . compact . join ( ' ' )
158184 end
159185
186+ def monthtext ( month )
187+ MONTH_NAMES [ month - 1 ]
188+ end
189+
160190 def all_weeks?
161191 bynweekday_option . all? { |option | option . ordinal . nil? }
162192 end
@@ -172,7 +202,7 @@ def weekdays?
172202 end
173203
174204 def _bymonth
175- add list ( this . options . bymonth , method ( :monthtext ) , 'and' )
205+ add list ( options . fetch ( : bymonth) , method ( :monthtext ) , 'and' )
176206 end
177207
178208 def _byweekday
Original file line number Diff line number Diff line change 26462646 it { expect ( rrule . humanize ) . to eq 'every month on the 1st Monday and last Friday for 7 times' }
26472647 end
26482648
2649+ context 'every year on January 1st' do
2650+ let ( :rule ) { 'FREQ=YEARLY;BYMONTH=1;BYMONTHDAY=1' }
2651+
2652+ it { expect ( rrule . humanize ) . to eq 'every year on January 1st' }
2653+ end
2654+
26492655 context 'every month on the 14th' do
26502656 let ( :rule ) { 'FREQ=MONTHLY;INTERVAL=1;BYMONTHDAY=14,15' }
26512657
You can’t perform that action at this time.
0 commit comments