super_tools 2.1.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,22 +3,22 @@ module SuperFormatter
3
3
  Head = Struct.new(:data) do
4
4
  def indexes
5
5
  @indexes ||= {
6
- order_id: data.index('訂單號碼'),
7
- order_created: data.index('訂單日期'),
8
- shipping_method: data.index('送貨方式'),
9
- payment_method: data.index('付款方式'),
10
- payment_status: data.index('付款狀態'),
11
- recipient: data.index('收件人'),
12
- mobile: data.index('收件人電話號碼'),
13
- store_id: data.index('全家服務編號 / 7-11 店號'),
14
- address: data.index('完整地址'),
15
- total_order_amount: data.index('訂單合計'),
16
- note: data.index('送貨備註'),
17
- item_title: data.index('商品名稱'),
18
- item_option: data.index('選項'),
19
- item_code: data.index('商品貨號'),
20
- item_qty: data.index('數量'),
21
- item_cost: data.index('商品成本')
6
+ order_id: data.index("訂單號碼"),
7
+ order_created: data.index("訂單日期"),
8
+ shipping_method: data.index("送貨方式"),
9
+ payment_method: data.index("付款方式"),
10
+ payment_status: data.index("付款狀態"),
11
+ recipient: data.index("收件人"),
12
+ mobile: data.index("收件人電話號碼"),
13
+ store_id: data.index("全家服務編號 / 7-11 店號"),
14
+ address: data.index("完整地址"),
15
+ total_order_amount: data.index("訂單合計"),
16
+ note: data.index("送貨備註"),
17
+ item_title: data.index("商品名稱"),
18
+ item_option: data.index("選項"),
19
+ item_code: data.index("商品貨號"),
20
+ item_qty: data.index("數量"),
21
+ item_cost: data.index("商品成本")
22
22
  }
23
23
  end
24
24
  end
@@ -1,16 +1,15 @@
1
- require 'super_formatter/import'
2
- require 'super_formatter/shopline/head'
3
- require 'super_formatter/shopline/row'
4
- require 'super_formatter/shopline/order'
1
+ require "super_formatter/import"
2
+ require "super_formatter/shopline/head"
3
+ require "super_formatter/shopline/row"
4
+ require "super_formatter/shopline/order"
5
+
5
6
  module SuperFormatter
6
7
  module Shopline
7
8
  class Import < ::SuperFormatter::Import
8
9
 
9
10
  callable do
10
11
  build_rows!(Head, Row)
11
-
12
12
  self.orders = merged_orders!.values
13
-
14
13
  self.orders
15
14
  end
16
15
 
@@ -1,4 +1,5 @@
1
- require 'warehouse'
1
+ require "warehouse"
2
+
2
3
  module SuperFormatter
3
4
  module Shopline
4
5
  class Order
@@ -13,7 +14,7 @@ module SuperFormatter
13
14
  delegate :complete?, to: :row
14
15
 
15
16
  def order_id
16
- row.order_id.gsub("#", '')
17
+ row.order_id.gsub("#", "")
17
18
  end
18
19
 
19
20
  def initialize(row)
@@ -23,13 +24,13 @@ module SuperFormatter
23
24
 
24
25
  def provider
25
26
  @provider ||= case
26
- when row.shipping_method.include?('7-11')
27
+ when row.shipping_method.include?("7-11")
27
28
  :UNIMART
28
- when row.shipping_method.include?('全家')
29
+ when row.shipping_method.include?("全家")
29
30
  :FAMI
30
- when row.shipping_method.include?('新竹')
31
+ when row.shipping_method.include?("新竹")
31
32
  :HCT
32
- when row.shipping_method.include?('黑貓')
33
+ when row.shipping_method.include?("黑貓")
33
34
  :TCAT
34
35
  else
35
36
  nil
@@ -58,7 +59,7 @@ module SuperFormatter
58
59
  end
59
60
 
60
61
  def cash_on_delivery?
61
- if row.payment_method.include?('取貨付款')
62
+ if row.payment_method.include?("取貨付款")
62
63
  true
63
64
  else
64
65
  false
@@ -70,7 +71,7 @@ module SuperFormatter
70
71
  end
71
72
 
72
73
  def paid?
73
- row.payment_status == '已付款'
74
+ row.payment_status == "已付款"
74
75
  end
75
76
 
76
77
  def items
@@ -1,8 +1,8 @@
1
- require 'super_formatter/row'
1
+ require "super_formatter/row"
2
+
2
3
  module SuperFormatter
3
4
  module Shopline
4
5
  class Row < ::SuperFormatter::Row
5
-
6
6
  end
7
7
  end
8
8
  end
@@ -3,10 +3,10 @@ module SuperFormatter
3
3
  Head = Struct.new(:data) do
4
4
  def indexes
5
5
  @indexes ||= {
6
- global_order_id: data.index('訂單編號'),
7
- mobile: data.index('手機(收)'),
8
- recipient: data.index('收件人'),
9
- tracking_code: data.index('託運單號')
6
+ global_order_id: data.index("訂單編號"),
7
+ mobile: data.index("手機(收)"),
8
+ recipient: data.index("收件人"),
9
+ tracking_code: data.index("託運單號")
10
10
  }
11
11
  end
12
12
  end
@@ -1,10 +1,10 @@
1
- require 'super_formatter/import'
2
- require 'super_formatter/hct/head'
3
- require 'super_formatter/hct/row'
1
+ require "super_formatter/import"
2
+ require "super_formatter/hct/head"
3
+ require "super_formatter/hct/row"
4
+
4
5
  module SuperFormatter
5
6
  module Tcat
6
7
  class Import < SuperFormatter::Import
7
-
8
8
  callable do
9
9
  build_rows!(Head, Row)
10
10
  end
@@ -1,16 +1,17 @@
1
- require 'super_formatter/row'
1
+ require "super_formatter/row"
2
+
2
3
  module SuperFormatter
3
4
  module Tcat
4
5
  class Row < ::SuperFormatter::Row
5
6
 
6
7
  def tracking_code
7
- (find(:tracking_code) || "").gsub("'", '')
8
+ (find(:tracking_code) || "").gsub("'", "")
8
9
  end
9
-
10
+
10
11
  def mobile
11
12
  @mobile ||= begin
12
13
  text = (find(:mobile) || "").gsub("'", "")
13
- if text[0] == '9' && text.length == 9
14
+ if text[0] == "9" && text.length == 9
14
15
  "0#{text}"
15
16
  else
16
17
  text
@@ -65,7 +65,7 @@ module SuperInteraction
65
65
  end
66
66
 
67
67
  def b_alert(class_type, text)
68
- cmd("if (typeof($.alert) == undefined) { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }")
68
+ cmd("if (typeof($.alert) === 'undefined') { alert('#{helpers.j(text)}'); } else { $.alert.#{class_type}('#{helpers.j(text)}'); }")
69
69
  end
70
70
 
71
71
  def cmd(js_code)
@@ -3,6 +3,8 @@ module SuperInteraction
3
3
  class Engine < Rails::Engine
4
4
  paths["app/views"] = "lib/super_interaction/views"
5
5
 
6
+ # NOTE: 需要確認底下的程式有無作用
7
+ # lib/super_interaction 底下並沒有 javascripts 目錄
6
8
  initializer 'beyond.assets.precompile' do |app|
7
9
  app.config.assets.paths << root.join('lib', 'super_interaction', 'javascripts').to_s
8
10
  end
@@ -0,0 +1,12 @@
1
+ module SuperProcess
2
+ module Basic
3
+
4
+ def method_missing(m, *args, &block)
5
+ if block_given?
6
+ new.public_send(m, *args, &block)
7
+ else
8
+ new.public_send(m, *args)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,4 +1,5 @@
1
- require 'virtus'
1
+ require "virtus"
2
+
2
3
  module SuperProcess
3
4
  class Core
4
5
  include ActiveModel::Validations
@@ -7,30 +8,38 @@ module SuperProcess
7
8
 
8
9
  ValidError = Class.new(StandardError)
9
10
 
10
- define_callbacks :validations, :task
11
+ CALLBACK_CALL = :"__super_process__call"
12
+ CALLBACK_TASK = :"__super_process__task"
13
+
14
+ # https://github.com/rails/rails/blob/v6.1.6/activesupport/lib/active_support/callbacks.rb#L97
15
+ # 這裡透過 define_callbacks define 了 CALLBACK_CALL 與 CALLBACK_TASK
16
+ # 卻沒有 set_callbacks,所以在 run_callbacks 時
17
+ # 會因為找不到儲存的 callback 而直接執行 block
18
+ # 這裡的用法必須注意 rails 內部或是使用此 class 的開發者
19
+ # 不可以使用 CALLBACK_CALL 與 CALLBACK_TASK 相同命名的 callback
20
+ # 否則會有不可預期的副作用
21
+ define_callbacks CALLBACK_CALL, CALLBACK_TASK
11
22
 
12
23
  def self.before_call(method_name)
13
- set_callback :validations, :before, method_name
24
+ set_callback CALLBACK_CALL, :before, method_name
14
25
  end
15
26
 
16
27
  def self.after_call(method_name)
17
- set_callback :validations, :after, method_name
28
+ set_callback CALLBACK_CALL, :after, method_name
18
29
  end
19
30
 
20
31
  def self.before_task(method_name)
21
- set_callback :task, :before, method_name
32
+ set_callback CALLBACK_TASK, :before, method_name
22
33
  end
23
34
 
24
35
  def self.after_task(method_name)
25
- set_callback :task, :after, method_name
36
+ set_callback CALLBACK_TASK, :after, method_name
26
37
  end
27
38
 
28
- def self.init(model_name, &block)
39
+ def self.init(model_name)
29
40
  attr_accessor model_name
30
-
31
- class_eval(&block) if block_given?
32
-
33
41
  define_method :initialize do |model|
42
+ super({})
34
43
  self.send("#{model_name}=", model)
35
44
  end
36
45
  end
@@ -40,10 +49,9 @@ module SuperProcess
40
49
  params.each do |attr, value|
41
50
  public_send("#{attr}=", value) if respond_to?("#{attr}=")
42
51
  end
43
- run_callbacks :validations do
52
+ run_callbacks CALLBACK_CALL do
44
53
  raise ValidError, "Validation Error" if valid? == false
45
-
46
- run_callbacks :task do
54
+ run_callbacks CALLBACK_TASK do
47
55
  instance_eval(&block)
48
56
  end
49
57
  end
@@ -63,20 +71,13 @@ module SuperProcess
63
71
  @result
64
72
  end
65
73
 
66
- def error_messages
67
- if errors.messages.values.present?
68
- errors.messages.values.first.first
69
- else
70
- ""
71
- end
74
+ def error_message
75
+ errors.messages.values.first.first if errors.messages.values.present?
72
76
  end
73
77
 
74
- def self.method_missing(m, *args, &block)
75
- if block_given?
76
- new.public_send(m, *args, &block)
77
- else
78
- new.public_send(m, *args)
79
- end
78
+ def error_messages
79
+ errors.messages.values.flatten
80
80
  end
81
+
81
82
  end
82
83
  end
@@ -1,11 +1,13 @@
1
- require 'searchkick'
1
+ # NOTE: 這個 class 完全沒有在 landing 或 xdelivery 出現過
2
+ require "searchkick"
3
+
2
4
  module SuperSearch
3
5
  class Scroll
4
6
  attr_accessor :expire_time, :size, :query
5
7
 
6
- # ScrollSearch.new(Member, '*', where: {}, order: {}, scroll: '5m', size: 10000)
7
- def initialize(model, term: '*', options: {})
8
- self.expire_time = options.delete(:scroll) || '5m'
8
+ # ScrollSearch.new(Member, "*", where: {}, order: {}, scroll: "5m", size: 10000)
9
+ def initialize(model, term: "*", options: {})
10
+ self.expire_time = options.delete(:scroll) || "5m"
9
11
 
10
12
  # 單次筆數不得超過 10000
11
13
  self.size = options.delete(:size).to_i
@@ -48,7 +50,7 @@ module SuperSearch
48
50
  # searchkick/query line: 104
49
51
  def handle_response(response)
50
52
  # 從 response 設定 scroll ID
51
- @scroll_id = response['_scroll_id']
53
+ @scroll_id = response["_scroll_id"]
52
54
  super
53
55
  end
54
56
 
@@ -66,9 +68,10 @@ module SuperSearch
66
68
 
67
69
  # 開始遍歷搜尋
68
70
  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
71
+ while r = query.execute and not r.response["hits"]["hits"].empty? do
72
+ block.call(r.results, r.total_count) if block
72
73
  end
73
74
  end
75
+
74
76
  end
77
+ end
@@ -1,7 +1,7 @@
1
- require 'iconv'
2
- require 'csv'
3
- require 'roo'
4
- require 'roo-xls'
1
+ require "csv"
2
+ require "roo"
3
+ require "roo-xls"
4
+
5
5
  module SuperSpreadsheet
6
6
  class Loader < SuperProcess::Core
7
7
  attr_accessor :file_path
@@ -20,14 +20,14 @@ module SuperSpreadsheet
20
20
  end
21
21
 
22
22
  def extension
23
- ::File.extname(file_path).split('.').last.force_encoding('utf-8').downcase
23
+ ::File.extname(file_path).split(".").last.force_encoding("utf-8").downcase
24
24
  end
25
25
 
26
26
  def valid_format
27
27
  if rows == false
28
- errors.add(:file, '檔案格式錯誤')
28
+ errors.add(:file, "檔案格式錯誤")
29
29
  elsif rows.flatten.empty?
30
- errors.add(:file, '檔案內容錯誤,空白檔案')
30
+ errors.add(:file, "檔案內容錯誤,空白檔案")
31
31
  end
32
32
  end
33
33
 
@@ -39,11 +39,11 @@ module SuperSpreadsheet
39
39
 
40
40
  def rows!
41
41
  case extension
42
- when 'xls'
42
+ when "xls"
43
43
  ::Roo::Excel.new(file_path).map { |row| convert_float_to_integer(row) }
44
- when 'xlsx'
44
+ when "xlsx"
45
45
  ::Roo::Excelx.new(file_path).map { |row| convert_float_to_integer(row) }
46
- when 'csv'
46
+ when "csv"
47
47
  ::CSV.parse(csv_content!)
48
48
  else
49
49
  false
@@ -55,10 +55,10 @@ module SuperSpreadsheet
55
55
  def csv_content!
56
56
  @decode_csv_content ||= begin
57
57
  csv_content_big5!
58
- rescue Iconv::IllegalSequence
58
+ rescue
59
59
  begin
60
60
  csv_content_big5_hkscs!
61
- rescue Iconv::IllegalSequence
61
+ rescue
62
62
  csv_content
63
63
  end
64
64
  end
@@ -71,11 +71,11 @@ module SuperSpreadsheet
71
71
  private
72
72
 
73
73
  def csv_content_big5!
74
- Iconv.new("utf-8", "Big5//TRANSLIT//IGNORE").iconv(csv_content)
74
+ csv_content.encode!(Encoding::UTF_8, Encoding::BIG5)
75
75
  end
76
76
 
77
77
  def csv_content_big5_hkscs!
78
- Iconv.new("utf-8", "Big5-HKSCS//TRANSLIT//IGNORE").iconv(csv_content)
78
+ csv_content.encode!(Encoding::UTF_8, Encoding::BIG5_HKSCS)
79
79
  end
80
80
 
81
81
  def convert_float_to_integer(row)
@@ -1,4 +1,4 @@
1
- require 'super_table/builder'
1
+ require "super_table/builder"
2
2
 
3
3
  module SuperTable
4
4
  module ActionView
@@ -10,15 +10,15 @@ module SuperTable
10
10
  table_responsive = options.delete(:responsive)
11
11
  table_size = options.delete(:size).to_s
12
12
 
13
- classes = ['table']
13
+ classes = ["table"]
14
14
  classes << options[:class] if options[:class]
15
15
  classes.push("table-hover") if is_hover && table.collection.present?
16
- classes.push("table-sm") if table_size == 'sm'
16
+ classes.push("table-sm") if table_size == "sm"
17
17
 
18
18
  options[:class] = classes.join(" ")
19
19
 
20
20
  case table_responsive.to_s
21
- when 'sm', 'md', 'lg', 'xl'
21
+ when "sm", "md", "lg", "xl"
22
22
  content_tag(:div, class: "table-responsive-#{table_responsive}") do
23
23
  render_table(table, options, &block)
24
24
  end
@@ -1,4 +1,5 @@
1
- require 'super_table/view_helpers'
1
+ require "super_table/view_helpers"
2
+
2
3
  module SuperTable
3
4
  class Builder
4
5
  include ViewHelpers
@@ -16,7 +17,7 @@ module SuperTable
16
17
  def heads(*args, &block)
17
18
  options = args.extract_options!
18
19
 
19
- classes = ['table-secondary']
20
+ classes = ["table-secondary"]
20
21
  classes << options[:class] if options[:class]
21
22
  options[:class] = classes.join(" ")
22
23
 
@@ -54,7 +55,7 @@ module SuperTable
54
55
 
55
56
  th(column_options) do
56
57
  concat(title)
57
- concat content_tag(:div, desc, class: 'small text-primary') if desc
58
+ concat content_tag(:div, desc, class: "small text-primary") if desc
58
59
  end
59
60
  end
60
61
 
@@ -99,7 +100,7 @@ module SuperTable
99
100
  def placeholder_row
100
101
  tr do
101
102
  content = table.placeholder || "尚無資料"
102
- td(content, colspan: table.columns.length, class: 'text-center')
103
+ td(content, colspan: table.columns.length, class: "text-center")
103
104
  end
104
105
  end
105
106
 
@@ -1,4 +1,4 @@
1
- require 'forwardable'
1
+ require "forwardable"
2
2
 
3
3
  module SuperTable
4
4
  class Record < Struct.new(:model)
@@ -1,3 +1,3 @@
1
1
  module SuperTools
2
- VERSION = '2.1.0'
3
- end
2
+ VERSION = "3.0.1"
3
+ end
data/lib/super_tools.rb CHANGED
@@ -1,57 +1,69 @@
1
1
  # RAILS LIBs
2
- require 'active_support'
3
- require 'active_model'
4
- require 'active_record'
5
- require 'action_view'
2
+ require "active_support"
3
+ require "active_model"
4
+ require "active_record"
5
+ require "action_view"
6
+
6
7
  # VERSION
7
8
  require "super_tools/version"
9
+
8
10
  # TASKS
9
11
  require "super_process/core"
12
+ require "super_process/basic"
13
+
10
14
  # FORMS
11
15
  require "super_spreadsheet/loader"
12
16
  require "super_form/basic"
13
17
  require "super_form/reform"
18
+
14
19
  # TABLES
15
20
  require "super_table/action_view"
16
21
  require "super_table/builder"
17
22
  require "super_table/record"
18
23
  require "super_table/tableable"
19
24
  require "super_table/view_helpers"
25
+
20
26
  # FORMATTER
21
- require 'super_formatter/import'
22
- require 'super_formatter/row'
27
+ require "super_formatter/import"
28
+ require "super_formatter/row"
29
+
23
30
  # FORMATTER (ECAN)
24
- require 'super_formatter/ecan/head'
25
- require 'super_formatter/ecan/row'
26
- require 'super_formatter/ecan/import'
31
+ require "super_formatter/ecan/head"
32
+ require "super_formatter/ecan/row"
33
+ require "super_formatter/ecan/import"
34
+
27
35
  # FORMATTER (TCAT)
28
- require 'super_formatter/tcat/head'
29
- require 'super_formatter/tcat/row'
30
- require 'super_formatter/tcat/import'
36
+ require "super_formatter/tcat/head"
37
+ require "super_formatter/tcat/row"
38
+ require "super_formatter/tcat/import"
39
+
31
40
  # FORMATTER (HCT)
32
- require 'super_formatter/hct/head'
33
- require 'super_formatter/hct/row'
34
- require 'super_formatter/hct/import'
41
+ require "super_formatter/hct/head"
42
+ require "super_formatter/hct/row"
43
+ require "super_formatter/hct/import"
44
+
35
45
  # FORMATTER (SHOPLINE)
36
- require 'super_formatter/shopline/head'
37
- require 'super_formatter/shopline/row'
38
- require 'super_formatter/shopline/order'
39
- require 'super_formatter/shopline/import'
46
+ require "super_formatter/shopline/head"
47
+ require "super_formatter/shopline/row"
48
+ require "super_formatter/shopline/order"
49
+ require "super_formatter/shopline/import"
50
+
40
51
  # SEARCH
41
- require 'super_search/scroll'
52
+ require "super_search/scroll"
53
+
42
54
  # ZIP CODE
43
- require 'super_zipcode/taiwan'
55
+ require "super_zipcode/taiwan"
56
+
44
57
  # INTERACTION
45
- require 'super_interaction/layout'
46
- require 'super_interaction/engine'
47
- require 'super_interaction/beyond'
48
- require 'super_interaction/beyond_helper'
49
- require 'super_interaction/bootstrap'
50
- require 'super_interaction/bootstrap_helper'
51
- # FORMATTER
52
- require 'super_logger/formatter'
58
+ require "super_interaction/layout"
59
+ require "super_interaction/engine"
60
+ require "super_interaction/beyond"
61
+ require "super_interaction/beyond_helper"
62
+ require "super_interaction/bootstrap"
63
+ require "super_interaction/bootstrap_helper"
64
+
53
65
  # Values
54
- require 'super_value/base'
66
+ require "super_value/base"
55
67
 
56
68
  module SuperTools
57
69
  end