postcode_gem 0.3.3 → 0.3.4

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: 47edb52adf4f0016a41ceb58113b2440577e03320247a6d90576f01cd99ebdc9
4
+ data.tar.gz: df5f088bb75f0c0ca7164b53b544af75c1ad8d8616dc6a6c65a014306e1ed507
5
5
  SHA512:
6
- metadata.gz: 8a10f74185d31c4501eac6b233765276ee947d941bd68535b0715467875fbe9d2c395495ec67b06b5342a3255aa73d3e172333cb447f4f7da31978cd4e58ab61
7
- data.tar.gz: efc440bec98dbbdcecd9b65d4a1f32079b71cf75b060cded39b862d9f68e71feca0f9da23e71992de7d34b64439ed6e68a2dd42a0006860164577b47ae502529
6
+ metadata.gz: 9d969bc0762746c13f263a6aa1ac18cf27c4c15e4b93250cb973ceb683e803d6dd599edebdb594d8be3b6cb4b4d66a3f7bf3856fb4ed27bb42f61116d5755904
7
+ data.tar.gz: ae136606f67e8605ec4de3b704a8122e19500961ba3f503d0ba16d5a7e4c93b5f7deba24453688355417ecc2e7af94736bcc53e0224229354557c0dcd20cd769
@@ -1,3 +1,3 @@
1
1
  module PostcodeGem
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
data/lib/postcode_gem.rb CHANGED
@@ -1,3 +1,37 @@
1
- require_relative 'postcode_gem/handle'
1
+ require_relative '../postcode_gem/version'
2
+ require "json"
3
+ require "tty-prompt"
4
+ require "pry"
2
5
 
3
- PostcodeGem.output_zipcode
6
+ module PostcodeGem
7
+ def self.select_country
8
+ @data = JSON.load(File.read('./data/postcode_areacode.json'))
9
+ attr_accessor :country, :city, :zipcode
10
+ prompt = TTY::Prompt.new
11
+ @country = prompt.select('Enter the country you want to select', %w(Vietnam England Japan))
12
+ end
13
+ def self.process_input
14
+ select_country
15
+ print "Enter the city or area code you want to search: "
16
+ @city_zipcode = gets.chomp
17
+ @firstWord = @city_zipcode.split('')[0]
18
+ end
19
+ def output_zipcode
20
+ process_input
21
+ @city = @data["#{@country}"].values
22
+ @zipcode = @data["#{@country}"].keys
23
+ @data_country = @data["#{@country}"]
24
+
25
+ if @data_country.has_key?(@city_zipcode)
26
+ puts @data_country.values_at("#{@city_zipcode}")
27
+ elsif @data_country.has_key?(@city_zipcode) == false && /[0-9]/.match(@firstWord)
28
+ puts @zipcode.map { |v| puts v if v.start_with?(@firstWord) }
29
+ end
30
+ if @data_country.has_value?(@city_zipcode)
31
+ puts @data_country.key(@city_zipcode)
32
+ elsif @data_country.has_value?(@city_zipcode) == false && /[a-z]/.match(@firstWord)
33
+ puts @city.map { |v| puts v if v.start_with?(@firstWord) }
34
+ end
35
+ end
36
+ module_function :output_zipcode
37
+ 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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - PhuongTr1501