pak_cities 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 703d631879a626f87eaf0deb2824a6a71b26bcabd794a33355e830a99f8a3077
4
+ data.tar.gz: 9faa31649e047760a7463a34ce9be35d6878f34dba641466c57f82ba3b585103
5
+ SHA512:
6
+ metadata.gz: ad546b843ea055926160181fd0b84f0e2610a3e39986ab9d5fa74cddf9fdd936ceb1904d2c42840af836ede0c5e8fb21ef3cd166c78cf43082706b16e33be12f
7
+ data.tar.gz: 42c1442cbdb531b1d74793b0dc1b643922feaa59e759e6d217301caf96a9c90e11fd4cf3301e8ad7c196c839b46025a6210ab105f2ac9995982626a290e6bedb
data/CHANGELOG.md ADDED
@@ -0,0 +1,55 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2026-01-08
9
+
10
+ ### Added
11
+
12
+ - Initial release of Pak Cities gem
13
+ - City class with proper methods (`to_s`, `to_h`, `inspect`, `==`, `hash`)
14
+ - Comprehensive query methods:
15
+ - `all` - Get all cities
16
+ - `count` - Total number of cities
17
+ - `find(name)` - Find city by name
18
+ - `find!(name)` - Find city or raise error
19
+ - `search(query)` - Fuzzy search by city name
20
+ - `where(conditions)` - Filter by multiple criteria
21
+ - `by_province(province)` - Get cities in a province
22
+ - `top_by_population(limit)` - Top cities by population
23
+ - `by_name(order:)` - Sort cities by name
24
+ - `by_population(order:)` - Sort cities by population
25
+ - `random(limit)` - Get random cities
26
+ - `provinces` - List all provinces
27
+ - `grouped_by_province` - Group cities by province
28
+ - `nearest_to(lat, lng, limit)` - Find nearest cities
29
+ - `within_bounds(...)` - Cities within bounding box
30
+ - `distance_between(city1, city2)` - Distance between two cities
31
+ - `same_province?(city1, city2)` - Check if same province
32
+ - `reload!` - Reload city data
33
+ - Statistical methods:
34
+ - `total_population` - Sum of all populations
35
+ - `average_population` - Average population
36
+ - `median_population` - Median population
37
+ - `population_by_province` - Population per province
38
+ - `cities_count_by_province` - City count per province
39
+ - `largest_city` - City with largest population
40
+ - `smallest_city` - City with smallest population
41
+ - Configuration system:
42
+ - Configurable distance units (km/miles)
43
+ - Configurable case sensitivity
44
+ - Distance calculator with Haversine formula
45
+ - Input validation for coordinates and parameters
46
+ - Custom error classes:
47
+ - `CityNotFoundError`
48
+ - `InvalidCoordinatesError`
49
+ - `InvalidConfigurationError`
50
+ - Comprehensive test suite (100 tests, 227 assertions)
51
+ - Full RuboCop compliance
52
+ - Support for Ruby >= 2.7.0
53
+ - Professional documentation and README
54
+
55
+ [0.1.0]: https://github.com/Talha380/pak_cities/releases/tag/v0.1.0
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Talha Razzaq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,228 @@
1
+ # PakCities
2
+
3
+ A professional Ruby gem providing comprehensive access to Pakistan cities data with powerful query methods, statistical analysis, and configurable options. Search cities by name, province, population, or find nearest cities by coordinates.
4
+
5
+ [![Ruby](https://img.shields.io/badge/ruby-%3E%3D%202.7.0-ruby.svg)](https://www.ruby-lang.org/)
6
+ [![Gem Version](https://badge.fury.io/rb/pak_cities.svg)](https://badge.fury.io/rb/pak_cities)
7
+
8
+ ## Features
9
+
10
+ - 🔍 **Comprehensive Query Methods** - Find, search, filter cities with ease
11
+ - 📊 **Statistical Analysis** - Population statistics, averages, medians
12
+ - 📍 **Geographic Calculations** - Find nearest cities, calculate distances
13
+ - ⚙️ **Configurable** - Distance units (km/miles), case sensitivity
14
+ - 🧪 **Well Tested** - 100% test coverage with 100+ tests
15
+ - 📝 **Professional Code** - Clean architecture, modular design
16
+ - 🚀 **Ruby 2.7+** - Compatible with modern Ruby versions
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ ```ruby
23
+ gem "pak_cities"
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ ```bash
29
+ bundle install
30
+ ```
31
+
32
+ Or install it yourself as:
33
+
34
+ ```bash
35
+ gem install pak_cities
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ### Basic Queries
41
+
42
+ ```ruby
43
+ require "pak_cities"
44
+
45
+ PakCities.all
46
+ PakCities.count
47
+
48
+ city = PakCities.find("Karachi")
49
+ city.name
50
+ city.province
51
+ city.latitude
52
+ city.longitude
53
+ city.population
54
+ ```
55
+
56
+ ### Search and Filter
57
+
58
+ ```ruby
59
+ PakCities.search("Lah")
60
+
61
+ PakCities.where(province: "Punjab")
62
+ PakCities.where(min_population: 1_000_000)
63
+ PakCities.where(max_population: 500_000)
64
+ PakCities.where(province: "Sindh", min_population: 1_000_000)
65
+
66
+ PakCities.by_province("Punjab")
67
+ ```
68
+
69
+ ### Population Queries
70
+
71
+ ```ruby
72
+ PakCities.top_by_population
73
+ PakCities.top_by_population(5)
74
+
75
+ PakCities.by_population(order: :desc)
76
+ PakCities.by_population(order: :asc)
77
+ ```
78
+
79
+ ### Sorting
80
+
81
+ ```ruby
82
+ PakCities.by_name(order: :asc)
83
+ PakCities.by_name(order: :desc)
84
+ ```
85
+
86
+ ### Random Selection
87
+
88
+ ```ruby
89
+ PakCities.random
90
+ PakCities.random(5)
91
+ ```
92
+
93
+ ### Province Operations
94
+
95
+ ```ruby
96
+ PakCities.provinces
97
+
98
+ PakCities.grouped_by_province
99
+
100
+ PakCities.same_province?("Karachi", "Hyderabad")
101
+ ```
102
+
103
+ ### Geographic Queries
104
+
105
+ ```ruby
106
+ PakCities.nearest_to(24.8608, 67.0104)
107
+ PakCities.nearest_to(31.558, 74.3507, 3)
108
+
109
+ PakCities.within_bounds(
110
+ min_lat: 24.0, max_lat: 26.0,
111
+ min_lng: 67.0, max_lng: 69.0
112
+ )
113
+
114
+ PakCities.distance_between("Karachi", "Lahore")
115
+ ```
116
+
117
+ ### Statistical Methods
118
+
119
+ ```ruby
120
+ PakCities.total_population
121
+ PakCities.average_population
122
+ PakCities.median_population
123
+
124
+ PakCities.population_by_province
125
+ PakCities.cities_count_by_province
126
+
127
+ PakCities.largest_city
128
+ PakCities.smallest_city
129
+ ```
130
+
131
+ ### Configuration
132
+
133
+ ```ruby
134
+ PakCities.configure do |config|
135
+ config.distance_unit = :miles
136
+ config.case_sensitive = true
137
+ end
138
+
139
+ PakCities.reset_configuration!
140
+ ```
141
+
142
+ ### Error Handling
143
+
144
+ ```ruby
145
+ begin
146
+ city = PakCities.find!("NonexistentCity")
147
+ rescue PakCities::CityNotFoundError => e
148
+ puts e.message
149
+ end
150
+
151
+ begin
152
+ PakCities.nearest_to(91, 67.0104)
153
+ rescue PakCities::InvalidCoordinatesError => e
154
+ puts e.message
155
+ end
156
+ ```
157
+
158
+ ## API Reference
159
+
160
+ ### Query Methods
161
+
162
+ | Method | Description | Returns |
163
+ |--------|-------------|---------|
164
+ | `all` | Get all cities | Array<City> |
165
+ | `count` | Total number of cities | Integer |
166
+ | `find(name)` | Find city by name (case-insensitive) | City or nil |
167
+ | `find!(name)` | Find city or raise error | City |
168
+ | `search(query)` | Fuzzy search by city name | Array<City> |
169
+ | `where(conditions)` | Filter by multiple criteria | Array<City> |
170
+ | `by_province(province)` | Get cities in a province | Array<City> |
171
+ | `top_by_population(limit)` | Top cities by population | Array<City> |
172
+ | `by_name(order:)` | Sort cities by name | Array<City> |
173
+ | `by_population(order:)` | Sort cities by population | Array<City> |
174
+ | `random(limit)` | Get random cities | Array<City> |
175
+ | `provinces` | List all provinces | Array<String> |
176
+ | `grouped_by_province` | Group cities by province | Hash |
177
+ | `nearest_to(lat, lng, limit)` | Find nearest cities | Array<City> |
178
+ | `within_bounds(...)` | Cities within bounding box | Array<City> |
179
+ | `distance_between(city1, city2)` | Distance between two cities | Float |
180
+ | `same_province?(city1, city2)` | Check if same province | Boolean |
181
+ | `reload!` | Reload city data | Array<City> |
182
+
183
+ ### Statistical Methods
184
+
185
+ | Method | Description | Returns |
186
+ |--------|-------------|---------|
187
+ | `total_population` | Sum of all populations | Integer |
188
+ | `average_population` | Average population | Float |
189
+ | `median_population` | Median population | Numeric |
190
+ | `population_by_province` | Population per province | Hash |
191
+ | `cities_count_by_province` | City count per province | Hash |
192
+ | `largest_city` | City with largest population | City |
193
+ | `smallest_city` | City with smallest population | City |
194
+
195
+ ### Configuration Options
196
+
197
+ | Option | Values | Default | Description |
198
+ |--------|--------|---------|-------------|
199
+ | `distance_unit` | `:km`, `:miles` | `:km` | Unit for distance calculations |
200
+ | `case_sensitive` | `true`, `false` | `false` | Case sensitivity for searches |
201
+
202
+ ### City Attributes
203
+
204
+ | Attribute | Type | Description |
205
+ |-----------|------|-------------|
206
+ | `name` | String | City name |
207
+ | `province` | String | Province name |
208
+ | `latitude` | Float | Geographic latitude |
209
+ | `longitude` | Float | Geographic longitude |
210
+ | `population` | Integer | Population (2025 estimate) |
211
+
212
+ ## Development
213
+
214
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
215
+
216
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
217
+
218
+ ## Contributing
219
+
220
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Talha380/pak_cities. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/Talha380/pak_cities/blob/master/CODE_OF_CONDUCT.md).
221
+
222
+ ## License
223
+
224
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
225
+
226
+ ## Code of Conduct
227
+
228
+ Everyone interacting in the PakCities project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Talha380/pak_cities/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
data/build_output.txt ADDED
@@ -0,0 +1,19 @@
1
+ WARNING: See https://guides.rubygems.org/specification-reference/ for help
2
+ ERROR: While executing gem ... (Gem::InvalidSpecificationException)
3
+ ["lib/pakistan_cities.rb", "lib/pakistan_cities/city.rb", "lib/pakistan_cities/configuration.rb", "lib/pakistan_cities/data.json", "lib/pakistan_cities/distance_calculator.rb", "lib/pakistan_cities/errors.rb", "lib/pakistan_cities/query.rb", "lib/pakistan_cities/statistics.rb", "lib/pakistan_cities/validators.rb", "lib/pakistan_cities/version.rb", "pakistan_cities.gemspec", "sig/pakistan_cities.rbs"] are not files
4
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/specification_policy.rb:514:in 'Gem::SpecificationPolicy#error'
5
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/specification_policy.rb:290:in 'Gem::SpecificationPolicy#validate_non_files'
6
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/specification_policy.rb:77:in 'Gem::SpecificationPolicy#validate_required!'
7
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/specification_policy.rb:47:in 'Gem::SpecificationPolicy#validate'
8
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/specification.rb:2501:in 'Gem::Specification#validate'
9
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/package.rb:298:in 'Gem::Package#build'
10
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/package.rb:137:in 'Gem::Package.build'
11
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/commands/build_command.rb:87:in 'Gem::Commands::BuildCommand#build_package'
12
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/commands/build_command.rb:77:in 'Gem::Commands::BuildCommand#build_gem'
13
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/commands/build_command.rb:68:in 'Gem::Commands::BuildCommand#execute'
14
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/command.rb:326:in 'Gem::Command#invoke_with_build_args'
15
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/command_manager.rb:252:in 'Gem::CommandManager#invoke_command'
16
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/command_manager.rb:193:in 'Gem::CommandManager#process_args'
17
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/command_manager.rb:151:in 'Gem::CommandManager#run'
18
+ /home/talha-razzaq/.rbenv/versions/3.4.5/lib/ruby/site_ruby/3.4.0/rubygems/gem_runner.rb:56:in 'Gem::GemRunner#run'
19
+ /home/talha-razzaq/.rbenv/versions/3.4.5/bin/gem:12:in '<main>'
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PakCities
4
+ class City
5
+ attr_reader :name, :province, :latitude, :longitude, :population
6
+
7
+ def initialize(name:, province:, latitude:, longitude:, population:)
8
+ @name = name
9
+ @province = province
10
+ @latitude = latitude.to_f
11
+ @longitude = longitude.to_f
12
+ @population = population.to_i
13
+ end
14
+
15
+ def to_s
16
+ "#{name}, #{province}"
17
+ end
18
+
19
+ def to_h
20
+ {
21
+ name: name,
22
+ province: province,
23
+ latitude: latitude,
24
+ longitude: longitude,
25
+ population: population
26
+ }
27
+ end
28
+
29
+ def inspect
30
+ "#<PakCities::City name=\"#{name}\" province=\"#{province}\" " \
31
+ "latitude=#{latitude} longitude=#{longitude} population=#{population}>"
32
+ end
33
+
34
+ def ==(other)
35
+ other.is_a?(City) &&
36
+ name == other.name &&
37
+ province == other.province
38
+ end
39
+ alias eql? ==
40
+
41
+ def hash
42
+ [name, province].hash
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PakCities
4
+ class Configuration
5
+ attr_accessor :case_sensitive
6
+ attr_reader :distance_unit
7
+
8
+ VALID_DISTANCE_UNITS = %i[km miles].freeze
9
+
10
+ def initialize
11
+ @distance_unit = :km
12
+ @case_sensitive = false
13
+ end
14
+
15
+ def distance_unit=(unit)
16
+ unit = unit.to_sym
17
+ unless VALID_DISTANCE_UNITS.include?(unit)
18
+ raise InvalidConfigurationError, "Invalid distance unit: #{unit}. Must be :km or :miles"
19
+ end
20
+
21
+ @distance_unit = unit
22
+ end
23
+ end
24
+
25
+ class << self
26
+ attr_writer :configuration
27
+
28
+ def configuration
29
+ @configuration ||= Configuration.new
30
+ end
31
+
32
+ def configure
33
+ yield(configuration)
34
+ end
35
+
36
+ def reset_configuration!
37
+ @configuration = Configuration.new
38
+ end
39
+ end
40
+ end