Simplify creating a map location from a heading

This commit is contained in:
Javi Martín
2023-03-07 17:47:05 +01:00
parent deb965bcce
commit aa5f5235de
2 changed files with 7 additions and 7 deletions

View File

@@ -181,7 +181,7 @@ module Budgets
end
def load_map
@map_location = MapLocation.load_from_heading(@heading) if @heading.present?
@map_location = MapLocation.from_heading(@heading) if @heading.present?
end
end
end

View File

@@ -17,11 +17,11 @@ class MapLocation < ApplicationRecord
}
end
def self.load_from_heading(heading)
map = new
map.zoom = Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM
map.latitude = heading.latitude.to_f if heading.latitude.present?
map.longitude = heading.longitude.to_f if heading.longitude.present?
map
def self.from_heading(heading)
new(
zoom: Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM,
latitude: (heading.latitude.to_f if heading.latitude.present?),
longitude: (heading.longitude.to_f if heading.longitude.present?)
)
end
end