world_voyager 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorldVoyager
4
+
5
+ VERSION = '0.1.0'
6
+
7
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'world_voyager/version'
4
+
5
+ module WorldVoyager
6
+
7
+ class Error < StandardError; end
8
+
9
+ DATABASE_PATH = 'lib/db/worldcities.csv'
10
+
11
+ @data = []
12
+
13
+ class << self
14
+
15
+ def install
16
+ require 'csv'
17
+
18
+ CSV.foreach(DATABASE_PATH, headers: true, header_converters: :symbol) do |row|
19
+ @data << row.to_h
20
+ end
21
+ end
22
+
23
+ def countries
24
+ install if @data.empty?
25
+
26
+ @data.map { |d| d[:country] }.uniq.sort
27
+ end
28
+
29
+ def districts(country)
30
+ install if @data.empty?
31
+
32
+ country_downcased = country.downcase
33
+ @data.select { |d| d[:country].downcase == country_downcased }.map { |d| d[:district] }.uniq.sort
34
+ end
35
+
36
+ def cities(district)
37
+ install if @data.empty?
38
+
39
+ district_downcased = district.downcase
40
+ @data.select { |d| d[:district].downcase == district_downcased }.map { |d| d[:city] }.uniq.sort
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,4 @@
1
+ module WorldVoyager
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: world_voyager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rui Barata
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: It uses simplemaps database to provide a list of countries and cities
14
+ around the world to use in your application.
15
+ email:
16
+ - ruipbarata@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - ".rubocop.yml"
23
+ - CHANGELOG.md
24
+ - CODE_OF_CONDUCT.md
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - lib/db/license.txt
31
+ - lib/db/worldcities.csv
32
+ - lib/db/worldcities.xlsx
33
+ - lib/world_voyager.rb
34
+ - lib/world_voyager/version.rb
35
+ - sig/world_voyager.rbs
36
+ homepage: https://github.com/rpbarata/world_voyager
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/rpbarata/world_voyager
41
+ source_code_uri: https://github.com/rpbarata/world_voyager
42
+ rubygems_mfa_required: 'true'
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.6.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.3.5
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Simple list of countries and cities around the world.
62
+ test_files: []