5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 14:31:42 +00:00
panel/app/models/metadata_document_date.rb

28 lines
568 B
Ruby
Raw Normal View History

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
2021-02-17 21:40:07 +00:00
def value_from_document
document.date
end
def indexable?
true
end
# 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
2021-02-17 21:40:07 +00:00
return (self[:value] = value_from_document || default_value) if self[:value].nil?
2019-08-13 23:33:57 +00:00
self[:value] = Date.iso8601(self[:value]).to_time if self[:value].is_a? String
self[:value]
2019-08-13 23:33:57 +00:00
end
2019-08-07 21:35:37 +00:00
end