super_tools 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +27 -8
- data/lib/super_interaction/command.rb +76 -0
- data/lib/super_interaction/controller_helper.rb +9 -0
- data/lib/super_logger/formatter.rb +15 -0
- data/lib/super_search/scroll.rb +75 -0
- data/lib/super_tools/version.rb +1 -1
- data/lib/super_tools.rb +8 -0
- data/lib/super_zipcode/taiwan.rb +131 -0
- data/super_tools.gemspec +1 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c151e245c7b1f268991fd0943ccf2501d746a3ca27787dea002256b52d8ab2bb
|
4
|
+
data.tar.gz: 05d30c55d616c97ab41d4124cd81f3a51d19189c40fa689eab75ad2c33473b5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8915c8773b2d3e40127e71ba1de6ff8088bd7e46b80f7e5f31cfca23ea12aa0cf9da85a0a6d42f28ec05e15e256f86c9f84703cec0b36d779b2b5a80b064b6c0
|
7
|
+
data.tar.gz: e0605f20e7e257f2514ac7e2ca2ab7e37cdd234b0fa47b12d144accece840b5c69b810a8831ec8e0ddc628fa1c98a33b2467a59f2c3162f76c1b04d0dda9b1d2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
super_tools (0.0.
|
4
|
+
super_tools (0.0.2)
|
5
5
|
actionview
|
6
6
|
activemodel
|
7
7
|
activerecord
|
@@ -15,6 +15,7 @@ PATH
|
|
15
15
|
reform-rails
|
16
16
|
roo
|
17
17
|
roo-xls
|
18
|
+
searchkick
|
18
19
|
spreadsheet
|
19
20
|
virtus (~> 1.0.5)
|
20
21
|
warehouse_items (~> 0.2.0)
|
@@ -71,9 +72,10 @@ GEM
|
|
71
72
|
declarative-option (< 0.2.0)
|
72
73
|
representable (>= 2.4.0, <= 3.1.0)
|
73
74
|
uber (< 0.2.0)
|
74
|
-
dry-configurable (0.
|
75
|
+
dry-configurable (0.8.2)
|
75
76
|
concurrent-ruby (~> 1.0)
|
76
|
-
|
77
|
+
dry-core (~> 0.4, >= 0.4.7)
|
78
|
+
dry-container (0.7.0)
|
77
79
|
concurrent-ruby (~> 1.0)
|
78
80
|
dry-configurable (~> 0.1, >= 0.1.3)
|
79
81
|
dry-core (0.4.7)
|
@@ -91,13 +93,24 @@ GEM
|
|
91
93
|
dry-equalizer (~> 0.2)
|
92
94
|
dry-inflector (~> 0.1, >= 0.1.2)
|
93
95
|
dry-logic (~> 0.4, >= 0.4.2)
|
96
|
+
elasticsearch (6.3.0)
|
97
|
+
elasticsearch-api (= 6.3.0)
|
98
|
+
elasticsearch-transport (= 6.3.0)
|
99
|
+
elasticsearch-api (6.3.0)
|
100
|
+
multi_json
|
101
|
+
elasticsearch-transport (6.3.0)
|
102
|
+
faraday
|
103
|
+
multi_json
|
94
104
|
equalizer (0.0.11)
|
95
105
|
erubi (1.8.0)
|
106
|
+
faraday (0.15.4)
|
107
|
+
multipart-post (>= 1.2, < 3)
|
96
108
|
fast_excel (0.2.6)
|
97
109
|
ffi (> 1.9, < 2)
|
98
110
|
ffi (1.10.0)
|
99
111
|
forwardable (1.2.0)
|
100
|
-
|
112
|
+
hashie (3.6.0)
|
113
|
+
i18n (1.6.0)
|
101
114
|
concurrent-ruby (~> 1.0)
|
102
115
|
ice_nine (0.11.2)
|
103
116
|
iconv (1.0.8)
|
@@ -107,7 +120,9 @@ GEM
|
|
107
120
|
method_source (0.9.2)
|
108
121
|
mini_portile2 (2.4.0)
|
109
122
|
minitest (5.11.3)
|
110
|
-
|
123
|
+
multi_json (1.13.1)
|
124
|
+
multipart-post (2.0.0)
|
125
|
+
nokogiri (1.10.2)
|
111
126
|
mini_portile2 (~> 2.4.0)
|
112
127
|
rack (2.0.7)
|
113
128
|
rack-test (1.1.0)
|
@@ -134,15 +149,19 @@ GEM
|
|
134
149
|
declarative (< 0.1.0)
|
135
150
|
declarative-option (< 0.2.0)
|
136
151
|
uber (< 0.2.0)
|
137
|
-
roo (2.
|
152
|
+
roo (2.8.2)
|
138
153
|
nokogiri (~> 1)
|
139
|
-
rubyzip (
|
154
|
+
rubyzip (>= 1.2.1, < 2.0.0)
|
140
155
|
roo-xls (1.2.0)
|
141
156
|
nokogiri
|
142
157
|
roo (>= 2.0.0, < 3)
|
143
158
|
spreadsheet (> 0.9.0)
|
144
159
|
ruby-ole (1.2.12.2)
|
145
160
|
rubyzip (1.2.2)
|
161
|
+
searchkick (4.0.0)
|
162
|
+
activemodel (>= 5)
|
163
|
+
elasticsearch (>= 6)
|
164
|
+
hashie
|
146
165
|
shoulda-context (1.2.2)
|
147
166
|
spreadsheet (1.2.3)
|
148
167
|
ruby-ole (>= 1.0)
|
@@ -170,4 +189,4 @@ DEPENDENCIES
|
|
170
189
|
super_tools!
|
171
190
|
|
172
191
|
BUNDLED WITH
|
173
|
-
1.
|
192
|
+
1.17.1
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module SuperInteraction
|
2
|
+
class Command < Struct.new(:context)
|
3
|
+
|
4
|
+
attr_accessor :commands
|
5
|
+
|
6
|
+
delegate :helpers, to: :context
|
7
|
+
|
8
|
+
def run
|
9
|
+
context.render js: (commands || []).join(";")
|
10
|
+
end
|
11
|
+
|
12
|
+
def bs_notice(message)
|
13
|
+
bs_alert('info', message)
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def bs_danger(message)
|
18
|
+
bs_alert('danger', message)
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def bs_success(message)
|
23
|
+
bs_alert('success', message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def alert(message)
|
27
|
+
cmd("alert('#{helpers.j(message)}');")
|
28
|
+
end
|
29
|
+
|
30
|
+
# modal 裡如果有 javascript 需寫在 .modal 層
|
31
|
+
# size: sm / md / lg / xl / xxl
|
32
|
+
# 注意:不要包 respond_to :js 會有問題
|
33
|
+
def modal(partial: nil, size: 'md', title: '', desc: '')
|
34
|
+
partial ||= context.action_name
|
35
|
+
modal_html = context.render_to_string(partial, layout: 'modal.html.haml', locals: { bs_modal_size: size, title: title, desc: desc })
|
36
|
+
cmd("$(function() { $.modal.show('#{helpers.j(modal_html)}'); });")
|
37
|
+
end
|
38
|
+
|
39
|
+
# 關閉 Modal
|
40
|
+
def close
|
41
|
+
cmd("$.modal.close();")
|
42
|
+
end
|
43
|
+
|
44
|
+
# 重新讀取頁面
|
45
|
+
def reload
|
46
|
+
cmd("Turbolinks.visit(location.toString());");
|
47
|
+
end
|
48
|
+
|
49
|
+
# 導入頁面
|
50
|
+
def redirect_to(url)
|
51
|
+
cmd("Turbolinks.visit('#{url}');");
|
52
|
+
end
|
53
|
+
|
54
|
+
def modal_saved_rediret_to(message, redirect_url)
|
55
|
+
close.alert(message).redirect_to(redirect_url)
|
56
|
+
end
|
57
|
+
|
58
|
+
def modal_saved_reload(message)
|
59
|
+
close.alert(message).reload
|
60
|
+
end
|
61
|
+
|
62
|
+
def ajax_get(url)
|
63
|
+
cmd("$.get('#{url}');")
|
64
|
+
end
|
65
|
+
|
66
|
+
def bs_alert(class_type, text)
|
67
|
+
cmd("if (typeof($.alert) == undefined) { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }")
|
68
|
+
end
|
69
|
+
|
70
|
+
def cmd(js_code)
|
71
|
+
self.commands ||= []
|
72
|
+
self.commands.push(js_code)
|
73
|
+
self
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SuperLogger
|
2
|
+
class Formatter < ::Logger::Formatter
|
3
|
+
include ActiveSupport::TaggedLogging::Formatter
|
4
|
+
|
5
|
+
def call(severity, timestamp, progname, msg)
|
6
|
+
format(
|
7
|
+
"%s[%-5s] %s%s\n",
|
8
|
+
timestamp.to_s,
|
9
|
+
severity,
|
10
|
+
progname ? "#{progname} -- " : nil,
|
11
|
+
"#{tags_text}#{msg}"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'searchkick'
|
2
|
+
module SuperSearch
|
3
|
+
class Scroll
|
4
|
+
attr_accessor :expire_time, :size, :query
|
5
|
+
|
6
|
+
# ScrollSearch.new(Member, '*', where: {}, order: {}, scroll: '5m', size: 10000)
|
7
|
+
def initialize(model, term: '*', options: {})
|
8
|
+
self.expire_time = options.delete(:scroll) || '5m'
|
9
|
+
|
10
|
+
# 單次筆數不得超過 10000
|
11
|
+
self.size = options.delete(:size).to_i
|
12
|
+
|
13
|
+
# TODO: 這裏多搜尋一次,解決效能問題
|
14
|
+
searchkick = model.search(term, { execute: false }.merge(options))
|
15
|
+
self.query = Searchkick::Query.new(searchkick.klass, searchkick.term, searchkick.options)
|
16
|
+
query_inject_hack
|
17
|
+
query.setup_scroll(expire_time)
|
18
|
+
query.setup_size(size)
|
19
|
+
end
|
20
|
+
|
21
|
+
# (hack) 改裝 Searchkick::Query
|
22
|
+
def query_inject_hack
|
23
|
+
query.instance_eval do
|
24
|
+
# 設定遍歷參數
|
25
|
+
def setup_scroll(scroll)
|
26
|
+
@scroll_id = nil
|
27
|
+
@scroll = scroll
|
28
|
+
end
|
29
|
+
|
30
|
+
# 設定遍歷 筆數/次
|
31
|
+
def setup_size(size)
|
32
|
+
@size = size
|
33
|
+
end
|
34
|
+
|
35
|
+
# searchkick/query line: 58
|
36
|
+
def params
|
37
|
+
options = { scroll: @scroll }
|
38
|
+
options.merge!(body: { size: @size }) if @size <= 10000 && @size > 0
|
39
|
+
super.deep_merge(options)
|
40
|
+
end
|
41
|
+
|
42
|
+
# searchkick/query line: 78
|
43
|
+
def execute
|
44
|
+
@execute = nil
|
45
|
+
super
|
46
|
+
end
|
47
|
+
|
48
|
+
# searchkick/query line: 104
|
49
|
+
def handle_response(response)
|
50
|
+
# 從 response 設定 scroll ID
|
51
|
+
@scroll_id = response['_scroll_id']
|
52
|
+
super
|
53
|
+
end
|
54
|
+
|
55
|
+
# searchkick/query line: 205
|
56
|
+
def execute_search
|
57
|
+
# 第一次用原本的 search 來取 scroll id, 第二次以後 scroll id 跑 scroll api
|
58
|
+
if @scroll_id.present?
|
59
|
+
Searchkick.client.scroll(body: { scroll_id: @scroll_id }, scroll: @scroll)
|
60
|
+
else
|
61
|
+
Searchkick.client.search(params)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# 開始遍歷搜尋
|
68
|
+
def search(&block)
|
69
|
+
while r = query.execute and not r.response['hits']['hits'].empty? do
|
70
|
+
block.call(r.results, r.total_count) if block
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
data/lib/super_tools/version.rb
CHANGED
data/lib/super_tools.rb
CHANGED
@@ -37,5 +37,13 @@ require 'super_formatter/shopline/head'
|
|
37
37
|
require 'super_formatter/shopline/row'
|
38
38
|
require 'super_formatter/shopline/order'
|
39
39
|
require 'super_formatter/shopline/import'
|
40
|
+
# ZIP CODE
|
41
|
+
require 'super_zipcode/taiwan'
|
42
|
+
# INTERACTION
|
43
|
+
require 'super_interaction/command'
|
44
|
+
require 'super_interaction/controller_helper'
|
45
|
+
# FORMATTER
|
46
|
+
require 'super_logger/formatter'
|
47
|
+
|
40
48
|
module SuperTools
|
41
49
|
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module SuperZipcode
|
2
|
+
class Taiwan
|
3
|
+
CITY_ZONE_ZIP_CODES = {
|
4
|
+
# 資料來源: jQuery TWzipcode v1.7.8
|
5
|
+
'基隆市' => {'仁愛區' => '200', '信義區' => '201', '中正區' => '202', '中山區' => '203', '安樂區' => '204', '暖暖區' => '205', '七堵區' => '206'},
|
6
|
+
'台北市' => {'中正區' => '100', '大同區' => '103', '中山區' => '104', '松山區' => '105', '大安區' => '106', '萬華區' => '108', '信義區' => '110', '士林區' => '111', '北投區' => '112', '內湖區' => '114', '南港區' => '115', '文山區' => '116'},
|
7
|
+
'新北市' => {
|
8
|
+
'萬里區' => '207', '金山區' => '208', '板橋區' => '220', '汐止區' => '221', '深坑區' => '222', '石碇區' => '223',
|
9
|
+
'瑞芳區' => '224', '平溪區' => '226', '雙溪區' => '227', '貢寮區' => '228', '新店區' => '231', '坪林區' => '232',
|
10
|
+
'烏來區' => '233', '永和區' => '234', '中和區' => '235', '土城區' => '236', '三峽區' => '237', '樹林區' => '238',
|
11
|
+
'鶯歌區' => '239', '三重區' => '241', '新莊區' => '242', '泰山區' => '243', '林口區' => '244', '蘆洲區' => '247',
|
12
|
+
'五股區' => '248', '八里區' => '249', '淡水區' => '251', '三芝區' => '252', '石門區' => '253'
|
13
|
+
},
|
14
|
+
'宜蘭縣' => {
|
15
|
+
'宜蘭市' => '260', '頭城鎮' => '261', '礁溪鄉' => '262', '壯圍鄉' => '263', '員山鄉' => '264', '羅東鎮' => '265',
|
16
|
+
'三星鄉' => '266', '大同鄉' => '267', '五結鄉' => '268', '冬山鄉' => '269', '蘇澳鎮' => '270', '南澳鄉' => '272',
|
17
|
+
'釣魚台列嶼' => '290'
|
18
|
+
},
|
19
|
+
'新竹市' => {'東區' => '300', '北區' => '300', '香山區' => '300'},
|
20
|
+
'新竹縣' => {
|
21
|
+
'竹北市' => '302', '湖口鄉' => '303', '新豐鄉' => '304', '新埔鎮' => '305', '關西鎮' => '306', '芎林鄉' => '307',
|
22
|
+
'寶山鄉' => '308', '竹東鎮' => '310', '五峰鄉' => '311', '橫山鄉' => '312', '尖石鄉' => '313', '北埔鄉' => '314',
|
23
|
+
'峨嵋鄉' => '315'
|
24
|
+
},
|
25
|
+
'桃園市' => {
|
26
|
+
'中壢區' => '320', '平鎮區' => '324', '龍潭區' => '325', '楊梅區' => '326', '新屋區' => '327', '觀音區' => '328',
|
27
|
+
'桃園區' => '330', '龜山區' => '333', '八德區' => '334', '大溪區' => '335', '復興區' => '336', '大園區' => '337',
|
28
|
+
'蘆竹區' => '338'
|
29
|
+
},
|
30
|
+
'苗栗縣' => {
|
31
|
+
'竹南鎮' => '350', '頭份市' => '351', '三灣鄉' => '352', '南庄鄉' => '353', '獅潭鄉' => '354', '後龍鎮' => '356',
|
32
|
+
'通霄鎮' => '357', '苑裡鎮' => '358', '苗栗市' => '360', '造橋鄉' => '361', '頭屋鄉' => '362', '公館鄉' => '363',
|
33
|
+
'大湖鄉' => '364', '泰安鄉' => '365', '銅鑼鄉' => '366', '三義鄉' => '367', '西湖鄉' => '368', '卓蘭鎮' => '369'
|
34
|
+
},
|
35
|
+
'台中市' => {
|
36
|
+
'中區' => '400', '東區' => '401', '南區' => '402', '西區' => '403', '北區' => '404', '北屯區' => '406', '西屯區' => '407', '南屯區' => '408',
|
37
|
+
'太平區' => '411', '大里區' => '412', '霧峰區' => '413', '烏日區' => '414', '豐原區' => '420', '后里區' => '421',
|
38
|
+
'石岡區' => '422', '東勢區' => '423', '和平區' => '424', '新社區' => '426', '潭子區' => '427', '大雅區' => '428',
|
39
|
+
'神岡區' => '429', '大肚區' => '432', '沙鹿區' => '433', '龍井區' => '434', '梧棲區' => '435', '清水區' => '436',
|
40
|
+
'大甲區' => '437', '外埔區' => '438', '大安區' => '439'
|
41
|
+
},
|
42
|
+
'彰化縣' => {
|
43
|
+
'彰化市' => '500', '芬園鄉' => '502', '花壇鄉' => '503', '秀水鄉' => '504', '鹿港鎮' => '505', '福興鄉' => '506',
|
44
|
+
'線西鄉' => '507', '和美鎮' => '508', '伸港鄉' => '509', '員林市' => '510', '社頭鄉' => '511', '永靖鄉' => '512',
|
45
|
+
'埔心鄉' => '513', '溪湖鎮' => '514', '大村鄉' => '515', '埔鹽鄉' => '516', '田中鎮' => '520', '北斗鎮' => '521',
|
46
|
+
'田尾鄉' => '522', '埤頭鄉' => '523', '溪州鄉' => '524', '竹塘鄉' => '525', '二林鎮' => '526', '大城鄉' => '527',
|
47
|
+
'芳苑鄉' => '528', '二水鄉' => '530'
|
48
|
+
},
|
49
|
+
'南投縣' => {
|
50
|
+
'南投市' => '540', '中寮鄉' => '541', '草屯鎮' => '542', '國姓鄉' => '544', '埔里鎮' => '545', '仁愛鄉' => '546',
|
51
|
+
'名間鄉' => '551', '集集鎮' => '552', '水里鄉' => '553', '魚池鄉' => '555', '信義鄉' => '556', '竹山鎮' => '557',
|
52
|
+
'鹿谷鄉' => '558'
|
53
|
+
},
|
54
|
+
'嘉義市' => {'東區' => '600', '西區' => '600'},
|
55
|
+
'嘉義縣' => {
|
56
|
+
'番路鄉' => '602', '梅山鄉' => '603', '竹崎鄉' => '604', '阿里山' => '605', '中埔鄉' => '606', '大埔鄉' => '607',
|
57
|
+
'水上鄉' => '608', '鹿草鄉' => '611', '太保市' => '612', '朴子市' => '613', '東石鄉' => '614', '六腳鄉' => '615',
|
58
|
+
'新港鄉' => '616', '民雄鄉' => '621', '大林鎮' => '622', '溪口鄉' => '623', '義竹鄉' => '624', '布袋鎮' => '625'
|
59
|
+
},
|
60
|
+
'雲林縣' => {
|
61
|
+
'斗南鎮' => '630', '大埤鄉' => '631', '虎尾鎮' => '632', '土庫鎮' => '633', '褒忠鄉' => '634', '東勢鄉' => '635',
|
62
|
+
'臺西鄉' => '636', '崙背鄉' => '637', '麥寮鄉' => '638', '斗六市' => '640', '林內鄉' => '643', '古坑鄉' => '646',
|
63
|
+
'莿桐鄉' => '647', '西螺鎮' => '648', '二崙鄉' => '649', '北港鎮' => '651', '水林鄉' => '652', '口湖鄉' => '653',
|
64
|
+
'四湖鄉' => '654', '元長鄉' => '655'
|
65
|
+
},
|
66
|
+
'台南市' => {
|
67
|
+
'中西區' => '700', '東區' => '701', '南區' => '702', '北區' => '704', '安平區' => '708', '安南區' => '709',
|
68
|
+
'永康區' => '710', '歸仁區' => '711', '新化區' => '712', '左鎮區' => '713', '玉井區' => '714', '楠西區' => '715',
|
69
|
+
'南化區' => '716', '仁德區' => '717', '關廟區' => '718', '龍崎區' => '719', '官田區' => '720', '麻豆區' => '721',
|
70
|
+
'佳里區' => '722', '西港區' => '723', '七股區' => '724', '將軍區' => '725', '學甲區' => '726', '北門區' => '727',
|
71
|
+
'新營區' => '730', '後壁區' => '731', '白河區' => '732', '東山區' => '733', '六甲區' => '734', '下營區' => '735',
|
72
|
+
'柳營區' => '736', '鹽水區' => '737', '善化區' => '741', '大內區' => '742', '山上區' => '743', '新市區' => '744',
|
73
|
+
'安定區' => '745'
|
74
|
+
},
|
75
|
+
'高雄市' => {
|
76
|
+
'新興區' => '800', '前金區' => '801', '苓雅區' => '802', '鹽埕區' => '803', '鼓山區' => '804', '旗津區' => '805',
|
77
|
+
'前鎮區' => '806', '三民區' => '807', '楠梓區' => '811', '小港區' => '812', '左營區' => '813',
|
78
|
+
'仁武區' => '814', '大社區' => '815', '東沙群島' => '817', '南沙群島' => '819', '岡山區' => '820', '路竹區' => '821',
|
79
|
+
'阿蓮區' => '822', '田寮區' => '823',
|
80
|
+
'燕巢區' => '824', '橋頭區' => '825', '梓官區' => '826', '彌陀區' => '827', '永安區' => '828', '湖內區' => '829',
|
81
|
+
'鳳山區' => '830', '大寮區' => '831', '林園區' => '832', '鳥松區' => '833', '大樹區' => '840', '旗山區' => '842',
|
82
|
+
'美濃區' => '843', '六龜區' => '844', '內門區' => '845', '杉林區' => '846', '甲仙區' => '847', '桃源區' => '848',
|
83
|
+
'那瑪夏區' => '849', '茂林區' => '851', '茄萣區' => '852'
|
84
|
+
},
|
85
|
+
'屏東縣' => {
|
86
|
+
'屏東市' => '900', '三地門鄉' => '901', '霧臺鄉' => '902', '瑪家鄉' => '903', '九如鄉' => '904', '里港鄉' => '905',
|
87
|
+
'高樹鄉' => '906', '鹽埔鄉' => '907', '長治鄉' => '908', '麟洛鄉' => '909', '竹田鄉' => '911', '內埔鄉' => '912',
|
88
|
+
'萬丹鄉' => '913', '潮州鎮' => '920', '泰武鄉' => '921', '來義鄉' => '922', '萬巒鄉' => '923', '崁頂鄉' => '924',
|
89
|
+
'新埤鄉' => '925', '南州鄉' => '926', '林邊鄉' => '927', '東港鎮' => '928', '琉球鄉' => '929', '佳冬鄉' => '931',
|
90
|
+
'新園鄉' => '932', '枋寮鄉' => '940', '枋山鄉' => '941', '春日鄉' => '942', '獅子鄉' => '943', '車城鄉' => '944',
|
91
|
+
'牡丹鄉' => '945', '恆春鎮' => '946', '滿州鄉' => '947'
|
92
|
+
},
|
93
|
+
'台東縣' => {
|
94
|
+
'臺東市' => '950', '綠島鄉' => '951', '蘭嶼鄉' => '952', '延平鄉' => '953', '卑南鄉' => '954', '鹿野鄉' => '955',
|
95
|
+
'關山鎮' => '956', '海端鄉' => '957', '池上鄉' => '958', '東河鄉' => '959', '成功鎮' => '961', '長濱鄉' => '962',
|
96
|
+
'太麻里鄉' => '963', '金峰鄉' => '964', '大武鄉' => '965', '達仁鄉' => '966'
|
97
|
+
},
|
98
|
+
'花蓮縣' => {
|
99
|
+
'花蓮市' => '970', '新城鄉' => '971', '秀林鄉' => '972', '吉安鄉' => '973', '壽豐鄉' => '974', '鳳林鎮' => '975',
|
100
|
+
'光復鄉' => '976', '豐濱鄉' => '977', '瑞穗鄉' => '978', '萬榮鄉' => '979', '玉里鎮' => '981', '卓溪鄉' => '982',
|
101
|
+
'富里鄉' => '983'
|
102
|
+
},
|
103
|
+
'金門縣' => {'金沙鎮' => '890', '金湖鎮' => '891', '金寧鄉' => '892', '金城鎮' => '893', '烈嶼鄉' => '894', '烏坵鄉' => '896'},
|
104
|
+
'連江縣' => {'南竿鄉' => '209', '北竿鄉' => '210', '莒光鄉' => '211', '東引鄉' => '212'},
|
105
|
+
'澎湖縣' => {'馬公市' => '880', '西嶼鄉' => '881', '望安鄉' => '882', '七美鄉' => '883', '白沙鄉' => '884', '湖西鄉' => '885'}
|
106
|
+
}
|
107
|
+
|
108
|
+
def self.code_regex
|
109
|
+
/(.{0,2}市|.{0,2}縣)(新市區|左鎮區|平鎮區|釣魚台列嶼|東沙群島|南沙群島|那瑪夏區|.{0,2}區|.{0,3}鄉|.{0,2}鎮|.{0,2}市)/
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.find_zip_code(address)
|
113
|
+
regex_match = code_regex =~ address
|
114
|
+
return nil if regex_match.blank?
|
115
|
+
|
116
|
+
city = $1
|
117
|
+
district = $2
|
118
|
+
|
119
|
+
return nil if CITY_ZONE_ZIP_CODES[city].blank?
|
120
|
+
CITY_ZONE_ZIP_CODES[city][district]
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.find_city(address)
|
124
|
+
regex_match = code_regex =~ address
|
125
|
+
return nil if regex_match.blank?
|
126
|
+
|
127
|
+
city = $1
|
128
|
+
CITY_ZONE_ZIP_CODES[city].present? && city
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/super_tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- eddie
|
@@ -290,6 +290,20 @@ dependencies:
|
|
290
290
|
- - "~>"
|
291
291
|
- !ruby/object:Gem::Version
|
292
292
|
version: 0.2.0
|
293
|
+
- !ruby/object:Gem::Dependency
|
294
|
+
name: searchkick
|
295
|
+
requirement: !ruby/object:Gem::Requirement
|
296
|
+
requirements:
|
297
|
+
- - ">="
|
298
|
+
- !ruby/object:Gem::Version
|
299
|
+
version: '0'
|
300
|
+
type: :runtime
|
301
|
+
prerelease: false
|
302
|
+
version_requirements: !ruby/object:Gem::Requirement
|
303
|
+
requirements:
|
304
|
+
- - ">="
|
305
|
+
- !ruby/object:Gem::Version
|
306
|
+
version: '0'
|
293
307
|
description: Rails 開發環境常用工具 Forms/Process/Spreadsheet
|
294
308
|
email:
|
295
309
|
- eddie.li.624@gmail.com
|
@@ -324,7 +338,11 @@ files:
|
|
324
338
|
- lib/super_formatter/tcat/head.rb
|
325
339
|
- lib/super_formatter/tcat/import.rb
|
326
340
|
- lib/super_formatter/tcat/row.rb
|
341
|
+
- lib/super_interaction/command.rb
|
342
|
+
- lib/super_interaction/controller_helper.rb
|
343
|
+
- lib/super_logger/formatter.rb
|
327
344
|
- lib/super_process/core.rb
|
345
|
+
- lib/super_search/scroll.rb
|
328
346
|
- lib/super_spreadsheet/loader.rb
|
329
347
|
- lib/super_table/action_view.rb
|
330
348
|
- lib/super_table/builder.rb
|
@@ -333,6 +351,7 @@ files:
|
|
333
351
|
- lib/super_table/view_helpers.rb
|
334
352
|
- lib/super_tools.rb
|
335
353
|
- lib/super_tools/version.rb
|
354
|
+
- lib/super_zipcode/taiwan.rb
|
336
355
|
- super_tools.gemspec
|
337
356
|
homepage: https://github.com/superlanding/super_tools
|
338
357
|
licenses:
|
@@ -354,7 +373,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
354
373
|
version: '0'
|
355
374
|
requirements: []
|
356
375
|
rubyforge_project:
|
357
|
-
rubygems_version: 2.
|
376
|
+
rubygems_version: 2.7.3
|
358
377
|
signing_key:
|
359
378
|
specification_version: 4
|
360
379
|
summary: Rails 開發環境常用工具 Forms/Process/Spreadsheet
|