2020-02-16 22:51:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Define un campo de coordenadas geográficas
|
|
|
|
class MetadataGeo < MetadataTemplate
|
|
|
|
def default_value
|
2020-11-11 18:29:12 +00:00
|
|
|
super || { 'lat' => nil, 'lng' => nil }
|
2020-02-16 22:51:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def empty?
|
2020-06-09 18:49:14 +00:00
|
|
|
value == default_value
|
2020-02-16 22:51:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2020-11-09 23:01:27 +00:00
|
|
|
return true unless changed?
|
2020-05-12 13:11:10 +00:00
|
|
|
return true if empty?
|
|
|
|
|
2020-06-09 18:49:14 +00:00
|
|
|
self[:value] = value.transform_values(&:to_f)
|
2020-08-20 23:38:31 +00:00
|
|
|
self[:value] = encrypt(value) if private?
|
2020-05-12 13:11:10 +00:00
|
|
|
|
|
|
|
true
|
2020-02-16 22:51:43 +00:00
|
|
|
end
|
2020-08-20 23:38:31 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def encrypt(value)
|
|
|
|
value.transform_values do |v|
|
|
|
|
super v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def decrypt(value)
|
|
|
|
value.transform_values do |v|
|
|
|
|
super v
|
|
|
|
end
|
|
|
|
end
|
2020-02-16 22:51:43 +00:00
|
|
|
end
|