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
|
|
|
|
{ 'lat' => nil, 'lng' => nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
def empty?
|
2020-05-12 13:11:10 +00:00
|
|
|
self[:value].nil? || value == default_value
|
2020-02-16 22:51:43 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
{ name => %i[lat lng] }
|
|
|
|
end
|
|
|
|
|
|
|
|
def save
|
2020-05-12 13:11:10 +00:00
|
|
|
return true if empty?
|
|
|
|
|
2020-02-16 22:51:43 +00:00
|
|
|
self[:value] = {
|
|
|
|
'lat' => self[:value]['lat'].to_f,
|
|
|
|
'lng' => self[:value]['lng'].to_f
|
|
|
|
}
|
2020-05-12 13:11:10 +00:00
|
|
|
|
|
|
|
true
|
2020-02-16 22:51:43 +00:00
|
|
|
end
|
|
|
|
end
|