Class: IceCube::MonthOfYearValidation
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 MonthOfYearValidation.
5
6
7
|
# File 'lib/ice_cube/validations/month_of_year.rb', line 5
def initialize(rule)
@months_of_year = rule.validations[:month_of_year]
end
|
Instance Method Details
#closest(date) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/ice_cube/validations/month_of_year.rb', line 14
def closest(date)
return nil if !@months_of_year || @months_of_year.empty?
months = @months_of_year.map do |m|
m > date.month ? m - date.month : 12 - date.month + m
end
months.compact!
goal = date
months.min.times { goal += TimeUtil.days_in_month(goal) * IceCube::ONE_DAY }
adjust(goal, date)
end
|
#to_ical ⇒ Object
32
33
34
|
# File 'lib/ice_cube/validations/month_of_year.rb', line 32
def to_ical
'BYMONTH=' << @months_of_year.join(',') unless @months_of_year.empty?
end
|
#to_s ⇒ Object
28
29
30
|
# File 'lib/ice_cube/validations/month_of_year.rb', line 28
def to_s
'in ' << @months_of_year.map { |m| Date::MONTHNAMES[m] }.join(', ') unless @months_of_year.empty?
end
|
#validate(date) ⇒ Object
9
10
11
12
|
# File 'lib/ice_cube/validations/month_of_year.rb', line 9
def validate(date)
return true if !@months_of_year || @months_of_year.empty?
@months_of_year.include?(date.month)
end
|