algerography 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,94 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+
4
+ require_relative "algerography/version"
5
+
6
+ module Algerography
7
+ class Error < StandardError; end
8
+
9
+
10
+ class French
11
+
12
+ def self.all_data_cities
13
+ states = []
14
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
15
+ source.each do |wilaya|
16
+ states << { code: wilaya['id'], city: wilaya['translations']['fr'] , area: wilaya['area'], districts: wilaya['districts'].map{|data| data.dig('fr') }}
17
+ end
18
+ states
19
+ end
20
+
21
+ def self.all_cities_districts
22
+ states = []
23
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
24
+ source.each do |wilaya|
25
+ states << wilaya['districts'].map{|data| data.dig('fr') }
26
+ end
27
+ states
28
+ end
29
+
30
+ def self.cities_names
31
+ states = []
32
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
33
+ source.each do |wilaya|
34
+ states << wilaya['translations']['fr']
35
+ end
36
+ states
37
+ end
38
+
39
+ def self.city_by_id id
40
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
41
+ source.select do |wilaya|
42
+ if wilaya['id'] == id
43
+ return { code: wilaya['id'], city: wilaya['translations']['fr'] , area: wilaya['area'], districts: wilaya['districts'].map{|data| data.dig('fr') }}
44
+ end
45
+ end
46
+ rescue
47
+ raise StandardError.new('given region could not be found')
48
+ end
49
+
50
+ end
51
+
52
+
53
+ class Arabic
54
+
55
+ def self.all_data_cities
56
+ states = []
57
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
58
+ source.each do |wilaya|
59
+ states << { code: wilaya['id'], city: wilaya['translations']['ar'] , area: wilaya['area'], districts: wilaya['districts'].map{|data| data.dig('ar') }}
60
+ end
61
+ states
62
+ end
63
+
64
+ def self.cities_names
65
+ states = []
66
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
67
+ source.each do |wilaya|
68
+ states << wilaya['translations']['ar']
69
+ end
70
+ states
71
+ end
72
+
73
+ def self.all_cities_districts
74
+ states = []
75
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
76
+ source.each do |wilaya|
77
+ states << wilaya['districts'].map{|data| data.dig('ar') }
78
+ end
79
+ states
80
+ end
81
+
82
+ def self.city_by_id id
83
+ source = YAML.load_file(File.join(File.dirname(__FILE__), 'algerography/wilaya_daira.yaml'))
84
+ source.select do |wilaya|
85
+ if wilaya['id'] == id
86
+ return { code: wilaya['id'], city: wilaya['translations']['ar'] , area: wilaya['area'], districts: wilaya['districts'].map{|data| data.dig('ar') }}
87
+ end
88
+ end
89
+ rescue
90
+ raise StandardError.new('given region could not be found')
91
+ end
92
+ end
93
+
94
+ end
@@ -0,0 +1,4 @@
1
+ module Algerography
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: algerography
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - youbaidjis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: 58 Wilayas. 548 Dairas. Support both Arabic and French languages. This
28
+ project was inspied by Laravel-algerography.
29
+ email:
30
+ - youba.etud@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - CHANGELOG.md
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - algerography.gemspec
42
+ - lib/algerography.rb
43
+ - lib/algerography/version.rb
44
+ - lib/algerography/wilaya_daira.yaml
45
+ - sig/algerography.rbs
46
+ homepage: https://github.com/youba1993/algerography
47
+ licenses:
48
+ - MIT
49
+ metadata:
50
+ homepage_uri: https://github.com/youba1993/algerography
51
+ changelog_uri: https://github.com/youba1993/algerography/blob/main/CHANGELOG.md
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.3.8
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: List and find Algerian cities
71
+ test_files: []