1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
module IceCube
module Validations::DayOfMonth
def day_of_month(*days)
days.flatten.each do |day|
unless day.is_a?(Integer)
raise ArgumentError, "expecting Integer value for day, got #{day.inspect}"
end
verify_alignment(day, :day, :day_of_month) { |error| raise error }
validations_for(:day_of_month) << Validation.new(day)
end
clobber_base_validations(:day, :wday)
self
end
class Validation < Validations::FixedValue
attr_reader :day
alias :value :day
def initialize(day)
@day = day
end
def key
:day_of_month
end
def type
:day
end
def dst_adjust?
true
end
def build_s(builder)
builder.piece(:day_of_month) << StringBuilder.nice_number(day)
end
def build_hash(builder)
builder.validations_array(:day_of_month) << day
end
def build_ical(builder)
builder['BYMONTHDAY'] << day
end
StringBuilder.register_formatter(:day_of_month) do |entries|
sentence = StringBuilder.sentence(entries)
str = IceCube::I18n.t('ice_cube.days_of_month', count: entries.size, segments: sentence)
IceCube::I18n.t('ice_cube.on', sentence: str)
end
end
end
end
|