uk_county_locator 0.1.0 → 0.1.1

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: 11e8ea68871c3be4cf5946c13058ea2948a25e5ace07914c6330ae576ac73fec
4
+ data.tar.gz: 7e1ec0119646dd94fdadb82f1085b67eab224f838d7fb3d7d309fb1850413052
5
5
  SHA512:
6
- metadata.gz: b1f68ea7ca094210af2fb2f3802e07226309bf612a6b8dd25d79c55c60baa7ee959bcc4262f794456d19db06173f2aa915c650de1650328b74f2538b082eebfc
7
- data.tar.gz: 4346bc8f9577b663a8b57a139d11ee8fab609a4c8373ecb8573845437dfd7d448f7f15781ba1efea4e0cc591d757c43b6db467e1937b64a4205882fc50cfc58a
6
+ metadata.gz: 3d407a46d1cfec80b9e14135b730617107cb857ea0be59bf1cd36b656742da1eb5303cc93fdea45fa2ff7e49ed877b01ae86efd575c722654dbb13279d79cc53
7
+ data.tar.gz: 3c818bac421056fc4f7078f8d5b648d459f1c47e0cac587a2882ca861688dacd8c0b7ccbc0a7698a9d0923db92bd362edfd99a3f29830c9897413d7836603b0f
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
 
@@ -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}"\
@@ -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.1'
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
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.1
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-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: geokit