2019-08-06 17:54:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Una lista de valores
|
|
|
|
class MetadataArray < MetadataTemplate
|
2023-10-06 13:53:19 +00:00
|
|
|
include Metadata::IndexableConcern
|
|
|
|
include Metadata::AlwaysPublicConcern
|
|
|
|
|
2019-08-06 17:54:17 +00:00
|
|
|
# El valor por defecto es una array vacía
|
2023-10-06 13:53:19 +00:00
|
|
|
#
|
|
|
|
# @return [Array]
|
2019-08-06 17:54:17 +00:00
|
|
|
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
|
|
|
|
2023-10-06 13:53:19 +00:00
|
|
|
# @return [String]
|
2021-05-06 15:33:28 +00:00
|
|
|
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
|
|
|
|
|
2020-02-12 21:24:54 +00:00
|
|
|
private
|
|
|
|
|
2023-10-06 14:39:58 +00:00
|
|
|
# Eliminar valores vacíos
|
|
|
|
#
|
|
|
|
# XXX: Por qué eliminábamos el punto del final?
|
|
|
|
#
|
|
|
|
# @todo Sanitizar otros valores
|
|
|
|
# @param :values [Array]
|
|
|
|
# @return [Array]
|
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
|