uk_county_locator 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f80e2a756a051daa471e931e2a6a873d3bcd6cb1cb70982615db766d640e121a
4
- data.tar.gz: 84f0c67cdc2e61b1a10b0a7df7de88f3d71c6ad304935f2527128c85c9f9e405
3
+ metadata.gz: 27a04a402e7e930016fd57dc017651e6d1af7ab70cf3beab8fc22516523d5029
4
+ data.tar.gz: a03327e72222c9be5125118eeaea3d8215dfd5ff614cff4ed0e826ea019c5a2a
5
5
  SHA512:
6
- metadata.gz: b1f68ea7ca094210af2fb2f3802e07226309bf612a6b8dd25d79c55c60baa7ee959bcc4262f794456d19db06173f2aa915c650de1650328b74f2538b082eebfc
7
- data.tar.gz: 4346bc8f9577b663a8b57a139d11ee8fab609a4c8373ecb8573845437dfd7d448f7f15781ba1efea4e0cc591d757c43b6db467e1937b64a4205882fc50cfc58a
6
+ metadata.gz: 52f26ec0c57ea50997202a192cd8aa44561f9da8bdc8f172702cf96dafe119d68aab36d125c1649eee6467c338ac7f8903f46ba85b1e4f36e0b9d0f7bde4e258
7
+ data.tar.gz: e8cbaf337486948decfc9ee7403bb182c25f075c865d5407703863b9549519978d4119f52292407ef40e3c8f7c78622550e3219c84a0d14c17422388e9ed353d
data/README.md CHANGED
@@ -65,6 +65,23 @@ puts polygon # => "iah@mrgyHs@tTkk@zc@jz@h{@kLnr@jo@rWal@}Rrk@za@UjMdhAb_@t|Bjn@
65
65
 
66
66
  The gem will support a number of common aliases for county names, in as far as is feasible, including shorthand abbreviations, such as 'Herts', 'Beds' and 'Bucks', as well as Welsh, Irish and Scots Gaelic languages, and more subtle alternative names.
67
67
 
68
+ ```ruby
69
+ polygon = UkCountyLocator.find_polygon(county: 'Londonderry', type: :ceremonial)
70
+ puts polygon # => "lhhk@geboIEHA?????_eAtQi`CtL}_..."
71
+
72
+ polygon = UkCountyLocator.find_polygon(county: 'Derry', type: :ceremonial)
73
+ puts polygon # => "lhhk@geboIEHA?????_eAtQi`CtL}_..."
74
+
75
+ polygon = UkCountyLocator.find_polygon(county: 'derry', type: :ceremonial)
76
+ puts polygon # => "lhhk@geboIEHA?????_eAtQi`CtL}_..."
77
+
78
+ polygon = UkCountyLocator.find_polygon(county: 'Co Derry', type: :ceremonial)
79
+ puts polygon # => "lhhk@geboIEHA?????_eAtQi`CtL}_..."
80
+
81
+ polygon = UkCountyLocator.find_polygon(county: 'Contae Dhoire', type: :ceremonial)
82
+ puts polygon # => "lhhk@geboIEHA?????_eAtQi`CtL}_..."
83
+ ```
84
+
68
85
  #### Fetching the County List
69
86
 
70
87
  It is also possible to fetch the list of counties, per type (alphabetised):
@@ -73,6 +90,50 @@ county_list = UkCountyLocator.county_list(type: :ceremonial)
73
90
  puts county_list # => ["Bedfordshire", "Berkshire", "Bristol", "Buckinghamshire", "Cambridgeshire", ...]
74
91
  ```
75
92
 
93
+ ## Errors & Rescues
94
+ The gem is able to sanitize data inputs to a point, and where invalid arguments are passed in, it is designed to error loudly.
95
+
96
+ For example, string numeric values can be passed in:
97
+ ```ruby
98
+ county = UkCountyLocator.find_county(lat: '51.5074', lng: '-0.1278')
99
+ puts county # => "Greater London"
100
+
101
+ county = UkCountyLocator.find_county(lat: 'foo', lng: 'bar')
102
+ # => UkCountyLocator::InvalidArgumentError (Invalid lat format: 'foo')
103
+
104
+ county = UkCountyLocator.find_county(lat: :foo, lng: :bar)
105
+ # => UkCountyLocator::InvalidArgumentError (Expected lat to be Numeric or a String, got Symbol)
106
+
107
+ county = UkCountyLocator.find_county(lat: nil, lng: nil)
108
+ # => UkCountyLocator::InvalidArgumentError (Expected lat to be Numeric or a String, got NilClass)
109
+
110
+ county = UkCountyLocator.find_county(lat: 51.5074, lng: -0.1278, type: 'Ceremonial')
111
+ puts county # => "Greater London"
112
+
113
+ county = UkCountyLocator.find_county(lat: 51.5074, lng: -0.1278, type: :postal)
114
+ # => UkCountyLocator::InvalidArgumentError (Invalid input: type must be one of :current, :ceremonial, :historic., or :all, got postal)
115
+
116
+ polygon = UkCountyLocator.find_polygon(county: 123)
117
+ # => UkCountyLocator::InvalidArgumentError (Expected county to be a String, got Integer)
118
+
119
+ polygon = UkCountyLocator.find_polygon(county: nil)
120
+ # => UkCountyLocator::InvalidArgumentError (Expected county to be a String, got NilClass)
121
+
122
+ county_list = UkCountyLocator.county_list(type: 'foo')
123
+ # => UkCountyLocator::InvalidArgumentError (Invalid input: type must be one of :current, :ceremonial, :historic., got foo)
124
+ ```
125
+ Note that the gem will infer the `:ceremonial` `:type` if an explicit `nil` value passed in:
126
+ ```ruby
127
+ county = UkCountyLocator.find_county(lat: 51.5074, lng: -0.1278, type: nil)
128
+ puts county # => "Greater London"
129
+
130
+ polygon = UkCountyLocator.find_polygon(county: 'Greater London', type: nil)
131
+ puts polygon # => "iah@mrgyHs@tTkk@zc@jz@h{@kLnr@jo@rWal@}Rrk@za@UjMdhAb_@t|Bjn@`h@|mAzs@kMl\\h..."
132
+
133
+ county_list = UkCountyLocator.county_list(type: nil)
134
+ puts county_list # => ["Bedfordshire", "Berkshire", "Bristol", "Buckinghamshire", "Cambridgeshire", ...]
135
+ ```
136
+
76
137
  ## County Type Definitions
77
138
  There are three sets of county data within the gem. The definitions between the three sets will differ between the four constituent countries of the United Kingdom, but are defined as per these Wikipedia links:
78
139
 
@@ -124,7 +185,7 @@ See image of Orkney Islands polygon:
124
185
 
125
186
 
126
187
  ### Rivers, Tributaries and Coastal Lines
127
- In order to compress the polygon areas, the boundaries that cover coastal lines have been more roughly drawn, with fewer coordinate points. The polygons are continuous where larger rivers and tributaries, where the same county on both sides. This means that coordinates that fall in the river will return the county as a result.
188
+ In order to compress the polygon areas, the boundaries that cover coastal lines have been more roughly drawn, with fewer coordinate points. The polygons are continuous where larger rivers and tributaries cut into a county area that falls on both sides of said river. This means that coordinates that fall in the river will return the county as a result.
128
189
 
129
190
  For example, coordinates that fall within the river Thames, where Greater London is on both sides of the river, will return 'Greater London' as the ceremonial county.
130
191
 
@@ -139,10 +200,6 @@ The data to compile these polygon areas has been taken from a number of sources,
139
200
  - [UK Ceremonial Counties](https://github.com/evansd/uk-ceremonial-counties/blob/master/uk-ceremonial-counties.geojson)
140
201
  - [The Association of British Counties](https://abcounties.com/)
141
202
 
142
- ## Performance Optimization
143
-
144
- The gem utilizes the `Parallel` gem to speed up polygon lookups.
145
-
146
203
  ## Compatibility
147
204
 
148
205
  The gem is tested against multiple versions of Rails using Appraisal, ensuring broad compatibility with different Ruby on Rails applications.
@@ -10,15 +10,16 @@ module UkCountyLocator
10
10
  def initialize(request:, type:, lat: nil, lng: nil, county: nil)
11
11
  @request = request
12
12
  @type = verified_type(type)
13
- @lat = parse_coordinate(lat, 'lat') if lat
14
- @lng = parse_coordinate(lng, 'lat') if lat
15
- @county = validated_county(county) if county
13
+ @lat = parse_coordinate(lat, 'lat') if @request == :county
14
+ @lng = parse_coordinate(lng, 'lat') if @request == :county
15
+ @county = validated_county(county) if @request == :polygon
16
16
  end
17
17
 
18
18
  private
19
19
 
20
20
  def verified_type(type)
21
21
  type = type&.downcase&.to_sym
22
+ return :ceremonial if type.nil?
22
23
  return type if valid_county_type?(type)
23
24
 
24
25
  raise InvalidArgumentError, "Invalid input: type must be one of :current, :ceremonial, :historic.#{all_message}"\
@@ -2,12 +2,10 @@
2
2
 
3
3
  require 'polylines'
4
4
  require 'geokit'
5
- require 'parallel'
6
5
 
7
6
  # PolylinesService handles the decoding of polygon polyline data and provides
8
7
  # functionality to check if a given point (latitude, longitude) lies within
9
- # any of the provided polygons. It supports batch processing of multiple
10
- # polygons using parallel processing to improve performance.
8
+ # any of the provided polygons.
11
9
  class PolylinesService
12
10
  def initialize(lat:, lng:)
13
11
  @point = Geokit::LatLng.new(lat, lng)
@@ -20,12 +18,9 @@ class PolylinesService
20
18
  def point_inside_polygon?(polygons)
21
19
  return nil if @point.nil?
22
20
 
23
- result = Parallel.map(polygons, in_processes: 4) do |name, polygon|
21
+ polygons.detect do |name, polygon|
24
22
  geo_polygon = Geokit::Polygon.new(polygon_to_array(polygon: polygon))
25
-
26
23
  geo_polygon.contains?(@point) ? name : nil
27
- end
28
-
29
- result.compact.first
24
+ end.first
30
25
  end
31
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UkCountyLocator
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -22,13 +22,13 @@ module UkCountyLocator
22
22
  end
23
23
 
24
24
  def self.find_polygon(county:, type: :ceremonial)
25
- validated_params = ArgumentValidator.new(request: :data, type: type, county: county)
25
+ validated_params = ArgumentValidator.new(request: :polygon, type: type, county: county)
26
26
 
27
27
  PolygonFetcher.new(type: validated_params.type).county_polygon(county)
28
28
  end
29
29
 
30
30
  def self.county_list(type: :ceremonial)
31
- validated_params = ArgumentValidator.new(request: :data, type: type)
31
+ validated_params = ArgumentValidator.new(request: :list, type: type)
32
32
 
33
33
  PolygonFetcher.new(type: validated_params.type).county_list
34
34
  end
@@ -35,7 +35,6 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  # Uncomment to register a new dependency of your gem
37
37
  spec.add_dependency 'geokit', '>= 1.0', '< 3.0'
38
- spec.add_dependency 'parallel', '>= 1.0', '< 3.0'
39
38
  spec.add_dependency 'polylines', '>= 0.1.1', '< 1.0'
40
39
 
41
40
  # For more information and examples about making a new gem, check out our
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uk_county_locator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edward Beesley
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-07 00:00:00.000000000 Z
11
+ date: 2025-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geokit
@@ -30,26 +30,6 @@ dependencies:
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'
33
- - !ruby/object:Gem::Dependency
34
- name: parallel
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '1.0'
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '3.0'
43
- type: :runtime
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: '1.0'
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '3.0'
53
33
  - !ruby/object:Gem::Dependency
54
34
  name: polylines
55
35
  requirement: !ruby/object:Gem::Requirement