postcode_gem 0.3.3 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3121cf7459c28fb6eda75b9552d0ba626ed1602ccf92e90a7e1da4efa25492dd
4
- data.tar.gz: 722e56207758896d7d7bd0e737963fda0ed7e9c15d1ae02a3fffdbaff377b4a2
3
+ metadata.gz: 0cbccb1683d859ebfaf71f7ac55e7f2b855f17d4ad81219c4ecc29f02fe194dd
4
+ data.tar.gz: '09d8345891920fa038a3ff246feed9ceb0ed9cee6f26eef36485c835a7ad83c3'
5
5
  SHA512:
6
- metadata.gz: 8a10f74185d31c4501eac6b233765276ee947d941bd68535b0715467875fbe9d2c395495ec67b06b5342a3255aa73d3e172333cb447f4f7da31978cd4e58ab61
7
- data.tar.gz: efc440bec98dbbdcecd9b65d4a1f32079b71cf75b060cded39b862d9f68e71feca0f9da23e71992de7d34b64439ed6e68a2dd42a0006860164577b47ae502529
6
+ metadata.gz: 6861b20678fb4c8de88b2f566eba37f0c696d90d3f70cc6d5f0497a4ee5edb16899da9e6ff08d8073436473af8eadafb30fca49adf77304c7a1fca5a630b3d7a
7
+ data.tar.gz: 7a53b2487b63de8a2a4e74ddc24e33818b6f1e6807e029d30aeeaa01927753d7e72069779b89ddccc7dfe7b4b37988253d9e0de09de1dff72eea3d6c55323573
@@ -1,3 +1,40 @@
1
- require_relative 'postcode_gem/handle'
1
+ require_relative '../lib/postcode_gem/version'
2
+ require "json"
3
+ require "tty-prompt"
4
+ require "pry"
2
5
 
3
- PostcodeGem.output_zipcode
6
+ module PostcodeGem
7
+ attr_accessor :country, :city, :zipcode
8
+ def output_zipcode
9
+ @data = JSON.load(File.read("#{Dir.pwd}/data/postcode_areacode.json"))
10
+ prompt = TTY::Prompt.new
11
+ @country = prompt.select('Enter the country you want to select', %w(Vietnam England Japan))
12
+ print "Enter the city or area code you want to search: "
13
+ @city_zipcode = gets.chomp
14
+ @firstWord = @city_zipcode.split('')[0]
15
+ @city = @data["#{@country}"].values
16
+ @zipcode = @data["#{@country}"].keys
17
+ @data_country = @data["#{@country}"]
18
+
19
+ if @data_country.has_key?(@city_zipcode)
20
+ puts @data_country.values_at("#{@city_zipcode}")
21
+ elsif @data_country.has_key?(@city_zipcode) == false && /[0-9]/.match(@firstWord)
22
+ puts @zipcode.map { |v| puts v if v.start_with?(@firstWord) }
23
+ end
24
+ if @data_country.has_value?(@city_zipcode)
25
+ puts @data_country.key(@city_zipcode)
26
+ elsif @data_country.has_value?(@city_zipcode) == false && /[a-z]/.match(@firstWord)
27
+ puts @city.map { |v| puts v if v.start_with?(@firstWord) }
28
+ end
29
+ end
30
+ module_function :output_zipcode
31
+ end
32
+
33
+ class Show
34
+ include PostcodeGem
35
+ def call_result
36
+ output_zipcode
37
+ end
38
+ end
39
+
40
+ Show.new.call_result
@@ -1,3 +1,3 @@
1
1
  module PostcodeGem
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postcode_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - PhuongTr1501