2019-08-08 18:28:23 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-07 21:35:37 +00:00
|
|
|
# Maneja la fecha del document
|
|
|
|
class MetadataDocumentDate < MetadataTemplate
|
|
|
|
# La fecha por defecto es ahora!
|
|
|
|
def default_value
|
|
|
|
Date.today.to_time
|
|
|
|
end
|
|
|
|
|
2020-02-12 21:24:54 +00:00
|
|
|
# El valor puede ser un Date, Time o una String en el formato
|
|
|
|
# "yyyy-mm-dd"
|
2019-08-07 21:35:37 +00:00
|
|
|
def value
|
2020-02-12 21:24:54 +00:00
|
|
|
return self[:value] if self[:value].is_a? Date
|
|
|
|
return self[:value] if self[:value].is_a? Time
|
2019-08-13 23:33:57 +00:00
|
|
|
|
2020-02-12 21:24:54 +00:00
|
|
|
begin
|
|
|
|
self[:value] = Date.parse(self[:value]).to_time
|
|
|
|
rescue ArgumentError, TypeError
|
|
|
|
document.date || default_value
|
|
|
|
end
|
2019-08-13 23:33:57 +00:00
|
|
|
end
|
2019-08-07 21:35:37 +00:00
|
|
|
end
|