postcode_gem 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/postcode_gem.rb +30 -32
- data/lib/postcode_gem/version.rb +1 -1
- data/postcode_gem.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc14cf37268efe4318eebfcfe4f6ee883286d9daa0ece5ae640d0e077f429ecb
|
4
|
+
data.tar.gz: 5b36dd891be6aff56afa4f7dae1bc8f00f7cc508726b8b9395e964b4e3c83678
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa6d689f6c730cd32b6d2cec2d8835a4cb97c0cfdd8aa14da0fdf30f9ab3d0836d3b145f6157a547f8631ad1f2820b00fe72bb947febd6afb224d12640b4126d
|
7
|
+
data.tar.gz: ab0540fe6ae211f3ad00b981b332ed611310ba878c482822a819d0b9e321bfd189831c0ae4a1f9dfc1594b174937520e8804fe7d59f45045bf551d9251c9077f
|
data/lib/postcode_gem.rb
CHANGED
@@ -1,42 +1,40 @@
|
|
1
1
|
require "json"
|
2
2
|
require "tty-prompt"
|
3
3
|
require "pry"
|
4
|
+
require_relative "../lib/postcode_gem/version"
|
5
|
+
|
4
6
|
|
5
7
|
module PostcodeGem
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
puts "
|
26
|
-
|
27
|
-
|
28
|
-
initialize
|
29
|
-
process_input
|
30
|
-
@country.each_pair do |key, val|
|
31
|
-
case
|
32
|
-
when @postcode_key == key then puts val
|
33
|
-
when @postcode_val == val then puts key
|
34
|
-
end
|
35
|
-
end
|
8
|
+
DATA = JSON.parse(File.read('../data/postcode_areacode.json'))
|
9
|
+
def self.select_country
|
10
|
+
attr_accessor :country, :city, :zipcode
|
11
|
+
prompt = TTY::Prompt.new
|
12
|
+
@country = prompt.select('Enter the country you want to select', %w(Vietnam England Japan))
|
13
|
+
end
|
14
|
+
def self.process_input
|
15
|
+
select_country
|
16
|
+
print "Enter the city or area code you want to search: "
|
17
|
+
@city_zipcode = gets.chomp
|
18
|
+
@firstWord = @city_zipcode.split('')[0]
|
19
|
+
end
|
20
|
+
def output_zipcode
|
21
|
+
process_input
|
22
|
+
@city = DATA["#{@country}"].values
|
23
|
+
@zipcode = DATA["#{@country}"].keys
|
24
|
+
@data_country = DATA["#{@country}"]
|
25
|
+
|
26
|
+
if @data_country.has_key?(@city_zipcode)
|
27
|
+
puts @data_country.values_at("#{@city_zipcode}")
|
28
|
+
elsif @data_country.has_key?(@city_zipcode) == false && /[0-9]/.match(@firstWord)
|
29
|
+
puts @zipcode.map { |v| puts v if v.start_with?(@firstWord) }
|
36
30
|
end
|
37
|
-
|
38
|
-
|
31
|
+
if @data_country.has_value?(@city_zipcode)
|
32
|
+
puts @data_country.key(@city_zipcode)
|
33
|
+
elsif @data_country.has_value?(@city_zipcode) == false && /[a-z]/.match(@firstWord)
|
34
|
+
puts @city.map { |v| puts v if v.start_with?(@firstWord) }
|
39
35
|
end
|
40
36
|
end
|
37
|
+
module_function :output_zipcode
|
41
38
|
end
|
42
39
|
|
40
|
+
PostcodeGem.output_zipcode
|
data/lib/postcode_gem/version.rb
CHANGED
data/postcode_gem.gemspec
CHANGED
@@ -3,7 +3,7 @@ require_relative 'lib/postcode_gem/version'
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "postcode_gem"
|
5
5
|
spec.version = PostcodeGem::VERSION
|
6
|
-
spec.authors = ["
|
6
|
+
spec.authors = ["PhuongTr1501"]
|
7
7
|
spec.email = ["phuong.tran@tomosia.com"]
|
8
8
|
|
9
9
|
spec.summary = %q{postcode country}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postcode_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- PhuongTr1501
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: this is postcode country of mine
|
14
14
|
email:
|