Module: TaiwanDistricts

Defined in:
lib/taiwan_districts.rb,
lib/taiwan_districts/engine.rb,
lib/taiwan_districts/version.rb,
app/controllers/taiwan_districts/data_controller.rb,
app/controllers/taiwan_districts/application_controller.rb

Defined Under Namespace

Classes: ApplicationController, DataController, Engine

Constant Summary collapse

TAIWAN =
'00000'
PATTERN =
/(\d{2})(\d{3})/
VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.city(code) ⇒ Object



22
23
24
# File 'lib/taiwan_districts.rb', line 22

def city(code)
  match(code)[1].ljust(5, '0')
end

.list(lang = 'zhtw', parent_id = '00000') ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/taiwan_districts.rb', line 8

def list(lang = 'zhtw', parent_id = '00000')
  result = []
  return result if parent_id.blank?
  city_id = city(parent_id)
  children = data(lang)
  children = children[city_id][:children] if children.has_key?(city_id)
  children.each_key do |id|
    result.push [children[id][:text], id]
  end

  result.sort! { |a, b| a[1] <=> b[1] }
  result
end