2020-03-24 22:11:30 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Un campo numérico
|
|
|
|
class MetadataNumber < MetadataTemplate
|
2023-10-06 13:53:19 +00:00
|
|
|
include Metadata::NonIndexableConcern
|
|
|
|
|
|
|
|
# El valor por defecto desde el esquema de datos o nada
|
|
|
|
#
|
|
|
|
# @return [Integer, nil]
|
2020-03-24 22:11:30 +00:00
|
|
|
def default_value
|
2020-11-11 18:29:12 +00:00
|
|
|
super || nil
|
2020-03-24 22:11:30 +00:00
|
|
|
end
|
|
|
|
|
2023-10-06 13:53:19 +00:00
|
|
|
# Convertir a Integer
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
2020-03-24 22:11:30 +00:00
|
|
|
def save
|
2020-11-09 23:01:27 +00:00
|
|
|
return true unless changed?
|
|
|
|
|
2020-03-24 22:11:30 +00:00
|
|
|
self[:value] = value.to_i
|
2020-08-20 23:38:31 +00:00
|
|
|
self[:value] = encrypt(value) if private?
|
2020-03-24 22:11:30 +00:00
|
|
|
|
|
|
|
true
|
|
|
|
end
|
2020-08-20 23:38:31 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def decrypt(value)
|
|
|
|
super(value).to_i
|
|
|
|
end
|
2020-03-24 22:11:30 +00:00
|
|
|
end
|