Module: CityPicker

Defined in:
lib/city_picker.rb,
lib/city_picker/engine.rb,
lib/city_picker/version.rb,
app/jobs/city_picker/application_job.rb,
app/models/city_picker/application_record.rb,
app/helpers/city_picker/application_helper.rb,
app/mailers/city_picker/application_mailer.rb,
app/controllers/city_picker/data_controller.rb,
app/controllers/city_picker/application_controller.rb

Defined Under Namespace

Modules: ApplicationHelper Classes: ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, DataController, Engine

Constant Summary collapse

VERSION =
'0.1.0'

Class Method Summary collapse

Class Method Details

.dataObject



5
6
7
8
9
10
11
# File 'lib/city_picker.rb', line 5

def data
  unless @list
    # Rails.logger.info "========= LIST  #{Time.now}"
    @list = JSON.parse(File.read("#{Engine.root}/db/data.json"))
  end
  @list
end

.get_address(codes = []) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/city_picker.rb', line 28

def get_address(codes = [])
  address = []
  codes.each do |code|
    address << get_by_code(code)
  end
  address.join('')
end

.get_by_code(code) ⇒ Object



23
24
25
26
# File 'lib/city_picker.rb', line 23

def get_by_code(code)
  values = data.values.flatten
  get(values, code)
end

.list(type, code) ⇒ Object



18
19
20
21
# File 'lib/city_picker.rb', line 18

def list(type, code)
  result = list_data(type, code)
  get_data(result)
end

.list_data(type, code) ⇒ Object



13
14
15
16
# File 'lib/city_picker.rb', line 13

def list_data(type, code)
  result = data[type]
  result.select{|a| a if a['parent'] == code} if type != 'province'
end