Module: PostcodeGem

Included in:
Show
Defined in:
lib/postcode_gem.rb,
lib/postcode_gem/version.rb

Constant Summary collapse

VERSION =
"0.3.14"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#cityObject

Returns the value of attribute city.



7
8
9
# File 'lib/postcode_gem.rb', line 7

def city
  @city
end

#countryObject

Returns the value of attribute country.



7
8
9
# File 'lib/postcode_gem.rb', line 7

def country
  @country
end

#zipcodeObject

Returns the value of attribute zipcode.



7
8
9
# File 'lib/postcode_gem.rb', line 7

def zipcode
  @zipcode
end

Class Method Details

.output_zipcodeObject



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 = PostcodeData::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.to_sym].values
  @zipcode = @data[@country.to_sym].keys
  @data_country = @data[@country.to_sym]

  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.to_s.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.to_s.start_with?(@firstWord) }
  end
end