2019-08-06 17:54:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Una lista de valores
|
|
|
|
class MetadataArray < MetadataTemplate
|
|
|
|
# El valor por defecto es una array vacía
|
|
|
|
def default_value
|
2020-11-11 18:29:12 +00:00
|
|
|
super || []
|
2019-08-06 17:54:17 +00:00
|
|
|
end
|
2019-08-13 23:33:57 +00:00
|
|
|
|
2021-02-11 15:13:18 +00:00
|
|
|
# Los Arrays no se pueden cifrar todavía
|
|
|
|
# TODO: Cifrar y decifrar arrays
|
|
|
|
def private?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2021-05-09 15:25:16 +00:00
|
|
|
# Solo los datos públicos se indexan, aunque MetadataArray no se cifra
|
|
|
|
# aun, dejamos esto preparado para la posteridad.
|
2021-05-06 15:33:28 +00:00
|
|
|
def indexable?
|
2021-05-09 15:25:16 +00:00
|
|
|
true && !private?
|
2021-05-06 15:33:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
value.join(', ')
|
|
|
|
end
|
|
|
|
|
2021-06-16 12:11:13 +00:00
|
|
|
# Obtiene el valor desde el documento, convirtiéndolo a Array si no lo
|
|
|
|
# era ya, por retrocompabilidad.
|
|
|
|
#
|
|
|
|
# @return [Array]
|
|
|
|
def document_value
|
2021-06-26 23:34:13 +00:00
|
|
|
[super].flatten(1).compact
|
2021-06-16 12:11:13 +00:00
|
|
|
end
|
|
|
|
|
2021-06-16 12:13:40 +00:00
|
|
|
alias indexable_values value
|
2021-05-06 16:00:05 +00:00
|
|
|
|
2020-02-12 21:24:54 +00:00
|
|
|
private
|
|
|
|
|
2021-02-11 19:16:25 +00:00
|
|
|
# TODO: Sanitizar otros valores
|
|
|
|
# XXX: Por qué eliminamos el punto del final?
|
2020-02-12 21:24:54 +00:00
|
|
|
def sanitize(values)
|
|
|
|
values.map do |v|
|
2021-02-11 19:16:25 +00:00
|
|
|
case v
|
|
|
|
when String then super(v).sub(/\.\z/, '')
|
|
|
|
else v
|
2020-02-12 21:24:54 +00:00
|
|
|
end
|
2021-02-11 15:13:18 +00:00
|
|
|
end.select(&:present?)
|
2020-02-12 21:24:54 +00:00
|
|
|
end
|
2019-08-06 17:54:17 +00:00
|
|
|
end
|