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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a04fbe6047ec986af166575c054a3c6ce6308627a3056910ed6f2022a6d8d19
4
- data.tar.gz: 7eeff1eeb4da29e3dd4bb1afff4234bc06231f717ebed640013ad31c1e8c972b
3
+ metadata.gz: bc14cf37268efe4318eebfcfe4f6ee883286d9daa0ece5ae640d0e077f429ecb
4
+ data.tar.gz: 5b36dd891be6aff56afa4f7dae1bc8f00f7cc508726b8b9395e964b4e3c83678
5
5
  SHA512:
6
- metadata.gz: 9020c7d55b120c73c84e0c1504b6429f52cff31689bdc46318c0b36b7d989cd9a5fb413d459bdae746d536c63b0f51063bba93e1d3505d34b431e0184b0438df
7
- data.tar.gz: 881296992916eaf28f166247a0805a30b552f3612e2345701b9349aad0930f5b1befcb81ff5b6295f505122931e9da270e51aaa650f947a52765c4ac6f86dbc2
6
+ metadata.gz: aa6d689f6c730cd32b6d2cec2d8835a4cb97c0cfdd8aa14da0fdf30f9ab3d0836d3b145f6157a547f8631ad1f2820b00fe72bb947febd6afb224d12640b4126d
7
+ data.tar.gz: ab0540fe6ae211f3ad00b981b332ed611310ba878c482822a819d0b9e321bfd189831c0ae4a1f9dfc1594b174937520e8804fe7d59f45045bf551d9251c9077f
@@ -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
- class ZipCodeArea
7
- def self.initialize
8
- prompt = TTY::Prompt.new
9
- @data_hash = JSON.parse(File.read('../data/postcode_areacode.json'))
10
- @select_country = prompt.select('Enter the country you want to select', %w(Vietnam England Japan))
11
- @arr_country = ["Vietnam", "England", "Japan"]
12
- @pos_country = @arr_country.index("#{@select_country}")
13
- @country = @data_hash.values[@pos_country]
14
- end
15
- def self.process_input
16
- # Processing input value
17
- print("Select the city or postcode? ")
18
- @postcode_city = gets.strip.downcase
19
- @split_submit = @postcode_city.split('')[0]
20
- if @split_submit.match(/[0-9]/)
21
- @postcode_key = @postcode_city.gsub(/\D/, '')
22
- elsif @split_submit.match(/[a-zA-Z]/)
23
- @postcode_val = @postcode_city.gsub(/[\W\d]/, '')
24
- end
25
- puts "Thanh pho ban chon la #{@postcode_val.upcase}."
26
- end
27
- def self.handler_city
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
- def self.handler_result
38
- handler_city
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
@@ -1,3 +1,3 @@
1
1
  module PostcodeGem
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -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 = ["Phtran0151"]
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.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
- - Phtran0151
7
+ - PhuongTr1501
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-31 00:00:00.000000000 Z
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: