Class: IceCube::DayValidation
Constant Summary
Constants inherited
from Validation
Validation::NUMBER_SUFFIX
Instance Method Summary
collapse
Methods inherited from Validation
#adjust, #nice_numbers, #sentence
Constructor Details
Returns a new instance of DayValidation.
5
6
7
8
|
# File 'lib/ice_cube/validations/day.rb', line 5
def initialize(rule)
@days = rule.validations[:day]
@rule = rule
end
|
Instance Method Details
#closest(date) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/ice_cube/validations/day.rb', line 15
def closest(date)
return nil if !@days || @days.empty?
days = @days.map do |d|
d > date.wday ? (d - date.wday) : (7 - date.wday + d)
end
days.compact!
goal = date + days.min * IceCube::ONE_DAY
adjust(goal, date)
end
|
#to_ical ⇒ Object
32
33
34
35
|
# File 'lib/ice_cube/validations/day.rb', line 32
def to_ical
days_dup = (@days - @rule.validations[:day_of_week].keys if @rule.validations[:day_of_week]) || @days 'BYDAY=' << days_dup.map { |d| IceCube::ICAL_DAYS[d] }.join(',') unless days_dup.empty?
end
|
#to_s ⇒ Object
27
28
29
30
|
# File 'lib/ice_cube/validations/day.rb', line 27
def to_s
days_dup = (@days - @rule.validations[:day_of_week].keys if @rule.validations[:day_of_week]) || @days 'on ' << sentence(days_dup.map { |d| Date::DAYNAMES[d] + 's' }) unless days_dup.empty?
end
|
#validate(date) ⇒ Object
10
11
12
13
|
# File 'lib/ice_cube/validations/day.rb', line 10
def validate(date)
return true if !@days || @days.empty?
@days.include?(date.wday)
end
|