postcode_gem 0.1.1 → 0.2.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a04fbe6047ec986af166575c054a3c6ce6308627a3056910ed6f2022a6d8d19
4
- data.tar.gz: 7eeff1eeb4da29e3dd4bb1afff4234bc06231f717ebed640013ad31c1e8c972b
3
+ metadata.gz: 48f8472d259d7553e3c36dd291cd5cac90c8ad6a4955b5f671c875146db23141
4
+ data.tar.gz: 85b76b7bee4846f006007f72f8367fe1ac5e7dc389aa7c49ca14e70c650425d7
5
5
  SHA512:
6
- metadata.gz: 9020c7d55b120c73c84e0c1504b6429f52cff31689bdc46318c0b36b7d989cd9a5fb413d459bdae746d536c63b0f51063bba93e1d3505d34b431e0184b0438df
7
- data.tar.gz: 881296992916eaf28f166247a0805a30b552f3612e2345701b9349aad0930f5b1befcb81ff5b6295f505122931e9da270e51aaa650f947a52765c4ac6f86dbc2
6
+ metadata.gz: f91df38e7fe2d27f90ffa2be34f7f14ea5d4654265310f74919587bffd4514cc363e408328093b2f4797494957c95aab39603168d937f83984e51d3c701a7854
7
+ data.tar.gz: ba8d6f234f3ac8b622ad48ef861cbe81707cd7e094d22e6627b4628a772112b3ece2652e066cfdbf4d68dfa6d604ea913f33afd69b79c9705869c96ae7d794fc
data/Gemfile CHANGED
@@ -8,3 +8,4 @@ gem "rspec", "~> 3.0"
8
8
  gem 'tty-spinner'
9
9
  gem 'tty-table'
10
10
  gem 'pry'
11
+ gem 'json'
@@ -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
+ def self.select_country
9
+ @data = JSON.load(File.read('./data/postcode_areacode.json'))
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.6"
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.6
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-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: this is postcode country of mine
14
14
  email: