Module: PostcodeGem
- Included in:
- Show
- Defined in:
- lib/postcode_gem.rb,
lib/postcode_gem/version.rb
Constant Summary collapse
- VERSION =
"0.3.11"
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#country ⇒ Object
Returns the value of attribute country.
-
#zipcode ⇒ Object
Returns the value of attribute zipcode.
Class Method Summary collapse
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
8 9 10 |
# File 'lib/postcode_gem.rb', line 8 def city @city end |
#country ⇒ Object
Returns the value of attribute country.
8 9 10 |
# File 'lib/postcode_gem.rb', line 8 def country @country end |
#zipcode ⇒ Object
Returns the value of attribute zipcode.
8 9 10 |
# File 'lib/postcode_gem.rb', line 8 def zipcode @zipcode end |
Class Method Details
.output_zipcode ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/postcode_gem.rb', line 9 def output_zipcode @data = PostcodeAreacode::DATA prompt = TTY::Prompt.new @country = prompt.select('Enter the country you want to select', %w(Vietnam England Japan)) print "Enter the city or area code you want to search: " @city_zipcode = gets.chomp @firstWord = @city_zipcode.split('')[0] @city = @data["#{@country}"].values @zipcode = @data["#{@country}"].keys @data_country = @data["#{@country}"] if @data_country.has_key?(@city_zipcode) puts @data_country.values_at("#{@city_zipcode}") elsif @data_country.has_key?(@city_zipcode) == false && /[0-9]/.match(@firstWord) puts @zipcode.map { |v| puts v if v.start_with?(@firstWord) } end if @data_country.has_value?(@city_zipcode) puts @data_country.key(@city_zipcode) elsif @data_country.has_value?(@city_zipcode) == false && /[a-z]/.match(@firstWord) puts @city.map { |v| puts v if v.start_with?(@firstWord) } end end |