diff --git a/app/helpers/host_info_helper.rb b/app/helpers/host_info_helper.rb index a2eaecc..64cd787 100644 --- a/app/helpers/host_info_helper.rb +++ b/app/helpers/host_info_helper.rb @@ -1,4 +1,6 @@ module HostInfoHelper + OSM_MARKER_URL = 'https://www.openstreetmap.org/?mlat=%s&mlon=%s#map=17/%s/%s'.freeze + def host_info server_name = request.server_name @@ -6,13 +8,25 @@ def host_info Supervisor::HostInfo.new(server_name).to_h end + location = format_location(info) + + # rubocop:disable Rails/OutputSafety + "Hostname: #{info[:hostname]} | IP: #{info[:ip]} | Location: #{location}".html_safe + # rubocop:enable Rails/OutputSafety + end + + private + + def format_location(info) location = %i[city region country org].filter_map do |key| next if info[key].blank? info[key] end.join(', ') - location = '-' if location.blank? - "Hostname: #{info[:hostname]} | IP: #{info[:ip]} | Location: #{location}" + return '-' if location.blank? + + lat, lon = info[:loc].split(',') + link_to(location, format(OSM_MARKER_URL, lat, lon, lat, lon), class: 'link-secondary') end end