Class: UkCountyLocator::Locator

Inherits:
Object
  • Object
show all
Defined in:
lib/uk_county_locator/locator.rb

Overview

Locator is responsible for determining the county data (current, ceremonial, or historic) for a given latitude and longitude. It handles both general county data retrieval for all county types or specific retrieval based on a provided type. The class also integrates with the PolylinesService to check if the point lies within the defined county polygons.

Instance Method Summary collapse

Constructor Details

#initialize(lat, lng, type: :all) ⇒ Locator

Returns a new instance of Locator.



14
15
16
17
18
# File 'lib/uk_county_locator/locator.rb', line 14

def initialize(lat, lng, type: :all)
  @lat = lat
  @lng = lng
  @type = type
end

Instance Method Details

#county_dataObject



20
21
22
23
24
25
26
27
28
# File 'lib/uk_county_locator/locator.rb', line 20

def county_data
  return specific_county_type(@type) unless @type == :all

  {
    current_county_or_unitary_authority: find_county_within(current_county_and_unitary_authority_polygons),
    ceremonial_county: find_county_within(ceremonial_county_polygons),
    historic_county: find_county_within(historic_county_polygons)
  }
end