uk_county_locator 0.1.0

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.
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'polylines'
4
+ require 'geokit'
5
+ require 'parallel'
6
+
7
+ # PolylinesService handles the decoding of polygon polyline data and provides
8
+ # 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.
11
+ class PolylinesService
12
+ def initialize(lat:, lng:)
13
+ @point = Geokit::LatLng.new(lat, lng)
14
+ end
15
+
16
+ def polygon_to_array(polygon:)
17
+ Polylines::Decoder.decode_polyline(polygon).map { |lng, lat| Geokit::LatLng.new(lat, lng) }
18
+ end
19
+
20
+ def point_inside_polygon?(polygons)
21
+ return nil if @point.nil?
22
+
23
+ result = Parallel.map(polygons, in_processes: 4) do |name, polygon|
24
+ geo_polygon = Geokit::Polygon.new(polygon_to_array(polygon: polygon))
25
+
26
+ geo_polygon.contains?(@point) ? name : nil
27
+ end
28
+
29
+ result.compact.first
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module UkCountyLocator
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'uk_county_locator/argument_validator'
4
+ require_relative 'uk_county_locator/locator'
5
+ require_relative 'uk_county_locator/polygon_fetcher'
6
+ require_relative 'uk_county_locator/version'
7
+
8
+ # UkCountyLocator module provides functionality for locating counties
9
+ # in the UK based on latitude and longitude coordinates. It supports
10
+ # different types of county information, including historical, ceremonial,
11
+ # and current county/ Unitary Authority data. The main method, `find_county`,
12
+ # returns the relevant county data for the provided coordinates and type.
13
+ # The method `find_polygon` will return the polygon for the requested county and type.
14
+ module UkCountyLocator
15
+ class Error < StandardError; end
16
+ class InvalidArgumentError < Error; end
17
+
18
+ def self.find_county(lat:, lng:, type: :ceremonial)
19
+ validated_params = ArgumentValidator.new(request: :county, type: type, lat: lat, lng: lng)
20
+
21
+ Locator.new(validated_params.lat, validated_params.lng, type: validated_params.type).county_data
22
+ end
23
+
24
+ def self.find_polygon(county:, type: :ceremonial)
25
+ validated_params = ArgumentValidator.new(request: :data, type: type, county: county)
26
+
27
+ PolygonFetcher.new(type: validated_params.type).county_polygon(county)
28
+ end
29
+
30
+ def self.county_list(type: :ceremonial)
31
+ validated_params = ArgumentValidator.new(request: :data, type: type)
32
+
33
+ PolygonFetcher.new(type: validated_params.type).county_list
34
+ end
35
+ end
@@ -0,0 +1,4 @@
1
+ module UkCountyLocator
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
Binary file
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/uk_county_locator/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'uk_county_locator'
7
+ spec.version = UkCountyLocator::VERSION
8
+ spec.authors = ['Edward Beesley']
9
+ spec.email = ['ed@homeflow.co.uk']
10
+
11
+ spec.summary = 'A Ruby gem that stores encoded polygon data for UK counties, ' \
12
+ 'with the ability to return county information for given coordinates.'
13
+
14
+ spec.homepage = 'https://github.com/EdBeese/uk_county_locator'
15
+ spec.license = 'MIT'
16
+ spec.required_ruby_version = '>= 2.6.0'
17
+
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/EdBeese/uk_county_locator'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/EdBeese/uk_county_locator/blob/main/CHANGELOG.md'
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(__dir__) do
27
+ `git ls-files -z`.split("\x0").reject do |f|
28
+ (File.expand_path(f) == __FILE__) ||
29
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
30
+ end
31
+ end
32
+ spec.bindir = 'exe'
33
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
34
+ spec.require_paths = ['lib']
35
+
36
+ # Uncomment to register a new dependency of your gem
37
+ spec.add_dependency 'geokit', '>= 1.0', '< 3.0'
38
+ spec.add_dependency 'parallel', '>= 1.0', '< 3.0'
39
+ spec.add_dependency 'polylines', '>= 0.1.1', '< 1.0'
40
+
41
+ # For more information and examples about making a new gem, check out our
42
+ # guide at: https://bundler.io/guides/creating_gem.html
43
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: uk_county_locator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Edward Beesley
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-03-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: geokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
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
+ - !ruby/object:Gem::Dependency
54
+ name: polylines
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.1.1
60
+ - - "<"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.0'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 0.1.1
70
+ - - "<"
71
+ - !ruby/object:Gem::Version
72
+ version: '1.0'
73
+ description:
74
+ email:
75
+ - ed@homeflow.co.uk
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".rspec"
81
+ - ".rubocop.yml"
82
+ - Appraisals
83
+ - CHANGELOG.md
84
+ - CODE_OF_CONDUCT.md
85
+ - LICENSE
86
+ - LICENSE.txt
87
+ - README.md
88
+ - Rakefile
89
+ - lib/uk_county_locator.rb
90
+ - lib/uk_county_locator/aliases/ceremonial_county_aliases.rb
91
+ - lib/uk_county_locator/aliases/current_county_and_unitary_authority_aliases.rb
92
+ - lib/uk_county_locator/aliases/historic_county_aliases.rb
93
+ - lib/uk_county_locator/argument_validator.rb
94
+ - lib/uk_county_locator/locator.rb
95
+ - lib/uk_county_locator/polygon_fetcher.rb
96
+ - lib/uk_county_locator/polygons/ceremonial_county_polygons.rb
97
+ - lib/uk_county_locator/polygons/current_county_and_unitary_authority_polygons.rb
98
+ - lib/uk_county_locator/polygons/historic_county_polygons.rb
99
+ - lib/uk_county_locator/polylines_service.rb
100
+ - lib/uk_county_locator/version.rb
101
+ - sig/uk_county_locator.rbs
102
+ - uk_county_locator-0.0.2.gem
103
+ - uk_county_locator.gemspec
104
+ homepage: https://github.com/EdBeese/uk_county_locator
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ allowed_push_host: https://rubygems.org
109
+ homepage_uri: https://github.com/EdBeese/uk_county_locator
110
+ source_code_uri: https://github.com/EdBeese/uk_county_locator
111
+ changelog_uri: https://github.com/EdBeese/uk_county_locator/blob/main/CHANGELOG.md
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.6.0
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.4.20
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: A Ruby gem that stores encoded polygon data for UK counties, with the ability
131
+ to return county information for given coordinates.
132
+ test_files: []