5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 17:46:22 +00:00
panel/app/models/metadata_date.rb

40 lines
877 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2019-08-08 18:28:23 +00:00
class MetadataDate < MetadataTemplate
# La fecha de hoy si no hay nada
#
# @return [Date,nil]
2019-11-07 16:06:40 +00:00
def default_value
case (dv = super)
when String
if dv.present?
begin
Date.parse(dv)
rescue Date::Error => e
ExceptionNotifier.notify_exception(e, data: { site: site.name, post: post.id, name:, type: })
nil
end
else
nil
end
else
Date.today
end
2019-11-07 16:06:40 +00:00
end
2020-12-24 19:13:29 +00:00
# Devuelve una fecha, si no hay ninguna es la fecha de hoy.
#
# @return [Date]
def value
return self[:value] if self[:value].is_a? Date
return self[:value] if self[:value].is_a? Time
2020-12-24 19:13:29 +00:00
return document_value || default_value unless self[:value]
begin
2020-12-24 19:13:29 +00:00
self[:value] = Date.parse self[:value]
rescue ArgumentError, TypeError
default_value
end
end
2019-08-08 18:28:23 +00:00
end