Skip to content

Commit 96ea94a

Browse files
committed
Cleanup method order: build_hash, build_ical last
1 parent 58fdcd0 commit 96ea94a

11 files changed

Lines changed: 52 additions & 51 deletions

lib/ice_cube/validations/day_of_month.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@ def build_s(builder)
3232
builder.piece(:day_of_month) << StringBuilder.nice_number(day)
3333
end
3434

35-
StringBuilder.register_formatter(:day_of_month) do |entries|
36-
str = "on the #{StringBuilder.sentence(entries)} "
37-
str << (entries.size == 1 ? 'day of the month' : 'days of the month')
38-
str
39-
end
40-
4135
def build_hash(builder)
4236
builder.validations_array(:day_of_month) << day
4337
end
@@ -46,6 +40,12 @@ def build_ical(builder)
4640
builder['BYMONTHDAY'] << day
4741
end
4842

43+
StringBuilder.register_formatter(:day_of_month) do |entries|
44+
str = "on the #{StringBuilder.sentence(entries)} "
45+
str << (entries.size == 1 ? 'day of the month' : 'days of the month')
46+
str
47+
end
48+
4949
end
5050

5151
end

lib/ice_cube/validations/day_of_week.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ def build_s(builder)
4646
builder.piece(:day_of_week) << "#{StringBuilder.nice_number(occ)} #{Date::DAYNAMES[day]}"
4747
end
4848

49-
StringBuilder.register_formatter(:day_of_week) do |segments|
50-
'on the ' + segments.join(' and ')
49+
def build_hash(builder)
50+
builder.validations[:day_of_week] ||= {}
51+
arr = (builder.validations[:day_of_week][day] ||= [])
52+
arr << occ
5153
end
5254

5355
def build_ical(builder)
@@ -57,10 +59,8 @@ def build_ical(builder)
5759
builder['BYDAY'] << "#{occ}#{ical_day}"
5860
end
5961

60-
def build_hash(builder)
61-
builder.validations[:day_of_week] ||= {}
62-
arr = (builder.validations[:day_of_week][day] ||= [])
63-
arr << occ
62+
StringBuilder.register_formatter(:day_of_week) do |segments|
63+
'on the ' + segments.join(' and ')
6464
end
6565

6666
end

lib/ice_cube/validations/day_of_year.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ def build_s(builder)
3737
builder.piece(:day_of_year) << StringBuilder.nice_number(day)
3838
end
3939

40-
StringBuilder.register_formatter(:day_of_year) do |entries|
41-
str = "on the #{StringBuilder.sentence(entries)} "
42-
str << (entries.size == 1 ? 'day of the year' : 'days of the year')
43-
str
44-
end
45-
4640
def build_hash(builder)
4741
builder.validations_array(:day_of_year) << day
4842
end
@@ -51,6 +45,12 @@ def build_ical(builder)
5145
builder['BYYEARDAY'] << day
5246
end
5347

48+
StringBuilder.register_formatter(:day_of_year) do |entries|
49+
str = "on the #{StringBuilder.sentence(entries)} "
50+
str << (entries.size == 1 ? 'day of the year' : 'days of the year')
51+
str
52+
end
53+
5454
end
5555

5656
end

lib/ice_cube/validations/hour_of_day.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ def type
2929
:hour
3030
end
3131

32-
StringBuilder.register_formatter(:hour_of_day) do |segments|
33-
str = "on the #{StringBuilder.sentence(segments)} "
34-
str << (segments.size == 1 ? 'hour of the day' : 'hours of the day')
35-
end
36-
3732
def build_s(builder)
3833
builder.piece(:hour_of_day) << StringBuilder.nice_number(hour)
3934
end
@@ -46,6 +41,11 @@ def build_ical(builder)
4641
builder['BYHOUR'] << hour
4742
end
4843

44+
StringBuilder.register_formatter(:hour_of_day) do |segments|
45+
str = "on the #{StringBuilder.sentence(segments)} "
46+
str << (segments.size == 1 ? 'hour of the day' : 'hours of the day')
47+
end
48+
4949
end
5050

5151
end

lib/ice_cube/validations/minute_of_hour.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ def type
2828
:min
2929
end
3030

31-
StringBuilder.register_formatter(:minute_of_hour) do |segments|
32-
str = "on the #{StringBuilder.sentence(segments)} "
33-
str << (segments.size == 1 ? 'minute of the hour' : 'minutes of the hour')
34-
end
35-
3631
def build_s(builder)
3732
builder.piece(:minute_of_hour) << StringBuilder.nice_number(minute)
3833
end
@@ -45,6 +40,11 @@ def build_ical(builder)
4540
builder['BYMINUTE'] << minute
4641
end
4742

43+
StringBuilder.register_formatter(:minute_of_hour) do |segments|
44+
str = "on the #{StringBuilder.sentence(segments)} "
45+
str << (segments.size == 1 ? 'minute of the hour' : 'minutes of the hour')
46+
end
47+
4848
end
4949

5050
end

lib/ice_cube/validations/minutely_interval.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ def build_s(builder)
3939
builder.base = interval == 1 ? 'Minutely' : "Every #{interval} minutes"
4040
end
4141

42+
def build_hash(builder)
43+
builder[:interval] = interval
44+
end
45+
4246
def build_ical(builder)
4347
builder['FREQ'] << 'MINUTELY'
4448
builder['INTERVAL'] << interval unless interval == 1
4549
end
4650

47-
def build_hash(builder)
48-
builder[:interval] = interval
49-
end
50-
5151
end
5252

5353
end

lib/ice_cube/validations/monthly_interval.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ def build_s(builder)
3333
builder.base = interval == 1 ? 'Monthly' : "Every #{interval} months"
3434
end
3535

36+
def build_hash(builder)
37+
builder[:interval] = interval
38+
end
39+
3640
def build_ical(builder)
3741
builder['FREQ'] << 'MONTHLY'
3842
builder['INTERVAL'] << interval unless interval == 1
3943
end
4044

41-
def build_hash(builder)
42-
builder[:interval] = interval
43-
end
44-
4545
end
4646

4747
end

lib/ice_cube/validations/schedule_lock.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@ def build_s(builder)
3434
end
3535

3636
# no -op
37-
def build_ical(builder)
37+
def build_hash(builder)
3838
end
3939

4040
# no -op
41-
def build_hash(builder)
41+
def build_ical(builder)
4242
end
43+
4344
end
4445

4546
end

lib/ice_cube/validations/secondly_interval.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ def build_s(builder)
3636
builder.base = interval == 1 ? 'Secondly' : "Every #{interval} seconds"
3737
end
3838

39+
def build_hash(builder)
40+
builder[:interval] = interval
41+
end
42+
3943
def build_ical(builder)
4044
builder['FREQ'] << 'SECONDLY'
4145
builder['INTERVAL'] << interval unless interval == 1
4246
end
4347

44-
def build_hash(builder)
45-
builder[:interval] = interval
46-
end
47-
4848
end
4949

5050
end

lib/ice_cube/validations/until.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ def validate(t, schedule)
3333
raise UntilExceeded if t > time
3434
end
3535

36-
def build_ical(builder)
37-
builder['UNTIL'] << IcalBuilder.ical_utc_format(time)
36+
def build_s(builder)
37+
builder.piece(:until) << "until #{time.strftime(IceCube.to_s_time_format)}"
3838
end
3939

4040
def build_hash(builder)
4141
builder[:until] = TimeUtil.serialize_time(time)
4242
end
4343

44-
def build_s(builder)
45-
builder.piece(:until) << "until #{time.strftime(IceCube.to_s_time_format)}"
44+
def build_ical(builder)
45+
builder['UNTIL'] << IcalBuilder.ical_utc_format(time)
4646
end
4747

4848
end

0 commit comments

Comments
 (0)