yol_common 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec20ea2bc4315db90f207d91f183f9ed950166605ba547405716168f3f544d1a
4
- data.tar.gz: 9731a41f9b1cb097c098d9c694d8d191a2b7b2d2995606998c6dac1d935d32ab
3
+ metadata.gz: 5f28f76dbd341a2dd3faad34d72370644ee5968a21139f4c30a6225a8b773e99
4
+ data.tar.gz: b08003df88f1a7bfb632031ca53658d86e5971ce7b2c4542574a086b47a698e7
5
5
  SHA512:
6
- metadata.gz: 7bccd16b584d70f285d29e6073cba494bfcf371e7e2d22ed2c75ea6d067b1f37502fccfb87dd7000cdd09e73a378f5fc469a9da7ef37cd68fa8ef31e8eff1cc4
7
- data.tar.gz: c69102883e0ed3a007e6d3443505b14d434c2d8a61760eee30c70452ed3372d9b0760b133ce98d0c77c8344a490e9e510fbcc965c63d9784ca33c409b76d3aee
6
+ metadata.gz: 3650db3c44f36d164c15423cf35141dbc6de9d500da05d71b1205cf5508e30bafbb09e97f446fc1522b6e9e07faa46bbc2ff21aabb13adb8dccd9f8356536f53
7
+ data.tar.gz: 1a0386f2619fca1b1839a46aa5eda93121ebd6ebc4ffd223fb32ad2f3c0236d2c9c379a4fb7cd644e7b083e069caffddf30333084b6731874415406fc5018aab
data/.gitignore CHANGED
@@ -1,15 +1,11 @@
1
+ .idea
2
+ *.gem
1
3
  *.rbc
2
- capybara-*.html
3
- .rspec
4
- /db/*.sqlite3
5
- /db/*.sqlite3-journal
6
- /db/*.sqlite3-[0-9]*
7
- /public/system
8
- /coverage/
9
- /spec/tmp
10
- *.orig
11
- rerun.txt
12
- pickle-email-*.html
4
+ *.DS_Store
5
+ *.swp
6
+ Gemfile.lock
7
+ GemfileLocal
8
+ GemfileLocal.lock
13
9
 
14
10
  # Ignore all logfiles and tempfiles.
15
11
  /log/*
@@ -65,3 +61,8 @@ yarn-debug.log*
65
61
  # Ignore uploaded files in development
66
62
  /storage/*
67
63
  !/storage/.keep
64
+
65
+ # Ignore pkg
66
+ /pkg/*
67
+
68
+
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- yol_common (0.0.2)
4
+ yol_common (0.0.3)
5
5
  oj
6
6
 
7
7
  GEM
8
8
  remote: https://gems.ruby-china.com/
9
9
  specs:
10
10
  diff-lcs (1.4.2)
11
- oj (3.11.3)
11
+ oj (3.13.7)
12
12
  rake (13.0.3)
13
13
  rspec (3.8.0)
14
14
  rspec-core (~> 3.8.0)
data/README.md CHANGED
@@ -1,2 +1,295 @@
1
- # yol_common
2
- common_methods
1
+ # YolCommon
2
+
3
+ 项目地址:http://oa.yolanda.hk:8002/server/yol_common
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/yol_common.svg)](http://badge.fury.io/rb/yol_common)
6
+
7
+ # 简单介绍
8
+
9
+ > YolCommon项目(公共方法集成)初衷是抽离公司ruby相关的公用代码块(如:邮箱/手机格式校验,节假日计算,七牛云上传下载等)
10
+
11
+ 其目的/好处主要两点:
12
+
13
+ ```ruby
14
+ 一是避免重复造轮问题;二是独智不抵群谋,集体评审优化,让每一个方法都异常精炼(除去杂质,提取精华)!
15
+ ```
16
+
17
+
18
+ ---
19
+
20
+
21
+ - [如何使用](#如何使用)
22
+ - - [安装依赖](#安装依赖)
23
+ - - [简单使用](#简单使用)
24
+ - [API文档](#api文档)
25
+ - - [线上文档](#线上文档)
26
+ - - [本地文档](#本地文档)
27
+ - [上传代码](#上传代码)
28
+ - - [目录介绍](#目录介绍)
29
+ - - - [添加依赖](#添加依赖)
30
+ - - - [更新版本](#更新版本)
31
+ - - - [单个方法](#单个方法)
32
+ - - - [系列方法](#系列方法)
33
+ - - - [重写方法](#重写方法)
34
+ - - [命名规则](#命名规则)
35
+ - - - [归类命名](#归类命名)
36
+ - - - [方法命名](#方法命名)
37
+ - - - [常量命名](#常量命名)
38
+ - [上传Gem](#上传Gem)
39
+
40
+ # 如何使用
41
+
42
+ ## 安装依赖
43
+
44
+ Add this line to your application's Gemfile:
45
+
46
+ ```ruby
47
+ # http://oa.yolanda.hk:9292为公司内部Gem源
48
+ source "http://oa.yolanda.hk:9292" do
49
+ gem 'yol_common', '~> 0.0.2'
50
+ end
51
+ ```
52
+
53
+ ## 简单使用
54
+ 引用模块
55
+ ```ruby
56
+ include YolCommon
57
+ ```
58
+ 使用方法
59
+ ```ruby
60
+ # 校验邮箱格式
61
+ Validator.email?("luojie@yolanda.hk")
62
+ => true
63
+ ```
64
+ ```ruby
65
+ # 计算量两日期间的工作日
66
+ end_at = Time.now
67
+ begin_at = Time.now - 30.days
68
+ business_days_between(begin_at, end_at)
69
+ => 22
70
+ ```
71
+ # <span id="api文档">API文档</span>
72
+
73
+ ## 线上文档
74
+
75
+ https://www.rubydoc.info/gems/yol_common/0.0.2
76
+
77
+ `说明:此地址为测试地址,供大家参考看看效果,正式地址待内部开发`
78
+
79
+
80
+ ## 本地文档
81
+
82
+ 正式地址开发前,可本地生成api文档,步骤如下:
83
+
84
+ ```cmd
85
+ # 1.本地拉取代码
86
+ git clone ssh://git@oa.yolanda.hk:22022/server/yol_common.git
87
+
88
+ # 2.同步最新代码
89
+ git pull
90
+
91
+ # 3.进入lib目录
92
+ cd yol_common/lib
93
+
94
+ # 4.利用rdoc命令生成文档
95
+ rdoc
96
+
97
+ # 5.浏览器打开生成的index.html
98
+ file: yol_common/lib/doc/index.html
99
+ ```
100
+
101
+
102
+
103
+ # 上传代码
104
+ 上传代码:指需要把一些新方法上传到yol_common或有更好的算法更新yol_common上的老方法;
105
+
106
+ ## 目录介绍
107
+
108
+ ### 添加依赖
109
+ File: yol_common/yol_common.gemspec
110
+
111
+ ```ruby
112
+ # 新方法依赖的gem需要使用“spec.add_dependency”添加
113
+ Gem::Specification.new do |spec|
114
+ ...
115
+ spec.add_development_dependency "bundler"
116
+ spec.add_development_dependency "rake"
117
+ spec.add_development_dependency "rspec"
118
+
119
+ spec.add_dependency 'oj'
120
+ end
121
+ ```
122
+
123
+ ### 更新版本
124
+ File: yolanda/yol_common/lib/yol_common/version.rb
125
+
126
+ ```ruby
127
+ # 每次更新代码,记得手动更新版本号
128
+ # 新版本号发布异常处理:及时删除源:http://oa.yolanda.hk:9292 上对应的版本;
129
+ module YolCommon
130
+ VERSION = "0.0.2"
131
+ end
132
+ ```
133
+
134
+ ### 单个方法
135
+ File: yolanda/yol_common/lib/yol_common/helper.rb
136
+
137
+ ```ruby
138
+ # help.rb为单个方法:非系列的,暂无归类的;
139
+ # 当单个方法积累到一定量,再进行归类处理;
140
+
141
+ module YolCommon
142
+
143
+ # 计算两日期间的工作日
144
+ ...
145
+ def business_days_between(date1, date2)
146
+ ...
147
+ end
148
+
149
+ end
150
+ ```
151
+
152
+ ### 系列方法
153
+ File: yolanda/yol_common/lib/yol_common/validator.rb
154
+
155
+ ```ruby
156
+ # validator.rb为系列方法:校验器,用于校验一些数据格式;
157
+
158
+ module YolCommon
159
+ ...
160
+ class Validator
161
+ # 邮箱
162
+ def self.email?(email)
163
+ end
164
+
165
+ # 手机
166
+ def self.mobile?(mobile)
167
+ end
168
+ ...
169
+ end
170
+ end
171
+ ```
172
+
173
+ ### 重写方法
174
+ File: yolanda/yol_common/lib/yol_common/range.rb
175
+
176
+ ```ruby
177
+ # range.rb为重写基础类Class::Range, 其目的是为了让范围range支持&符号查询交集;
178
+ # 重写前,&可用于 [1, 2] & [2, 3] = [2]
179
+ # 重写后,&也可用于 (1..10) & (5..15)
180
+
181
+ class Range
182
+ ...
183
+ alias_method :&,:intersection
184
+ end
185
+ ```
186
+
187
+
188
+ ## 命名规则
189
+
190
+ https://ruby-china.org/wiki/coding-style#%E5%91%BD%E5%90%8D
191
+
192
+ ### 归类命名
193
+
194
+
195
+ 使用CamelCase(駝峰式大小寫)的形式给类和模块命名。
196
+
197
+ (保持使用缩略首字母大写的方式如 HTTP, RFC, XML)
198
+
199
+ ```ruby
200
+ class SomeClass
201
+ ...
202
+ end
203
+
204
+ class SomeXML
205
+ ...
206
+ end
207
+ ```
208
+
209
+
210
+ ##### 举例 校验器
211
+
212
+ 直译:Validator
213
+
214
+ ```ruby
215
+ # file: yolanda/yol_common/lib/yol_common/validator.rb
216
+ module YolCommon
217
+ class Validator
218
+ ...
219
+ end
220
+ end
221
+ ```
222
+
223
+
224
+ ##### 举例 七牛云
225
+
226
+ 参考三方文档:https://developer.qiniu.com/kodo/1304/ruby
227
+
228
+ 便于区分添加Yol:YolQiniu
229
+
230
+ ```ruby
231
+ # file: yolanda/yol_common/lib/yol_common/yol_qiniu.rb
232
+ module YolCommon
233
+ class YolQiniu
234
+ ...
235
+ end
236
+ end
237
+ ```
238
+
239
+
240
+ ### 方法命名
241
+
242
+ snake_case的形式给变量和方法命名
243
+
244
+
245
+ ```
246
+ :some_symbol
247
+
248
+ def some_method
249
+ ...
250
+ end
251
+ ```
252
+
253
+
254
+
255
+ mobile?
256
+
257
+ "?"用于获取布尔型变量true/false
258
+
259
+ ```ruby
260
+ def self.email?(email)
261
+ return false if email.length <= 3 || email.length >= 255
262
+ return true if email.to_s =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i rescue nil
263
+ false
264
+ end
265
+ ```
266
+
267
+ ### 常量命名
268
+
269
+ 使用SCREAMING_SNAKE_CASE给常量命名。
270
+
271
+
272
+ ### 注释格式
273
+
274
+ ```
275
+ # 计算两日期间的工作日
276
+ ## @param [Date] 日期 Thu, 22 Apr 2021
277
+ ## @return [Int] 天数 5
278
+ ## @author luojie
279
+ ## @date 2021-03-30
280
+ def business_days_between(date1, date2)
281
+ business_days = 0
282
+ date = date2
283
+ while date > date1
284
+ business_days = business_days + 1 unless date.saturday? or date.sunday?
285
+ date = date - 1.day
286
+ end
287
+ business_days
288
+ end
289
+ ```
290
+
291
+
292
+ `说明:命名规范等遗漏处大家一起补充`
293
+
294
+ # 上传Gem
295
+ http://oa.yolanda.hk:9292
@@ -0,0 +1,28 @@
1
+ module YolCommon
2
+
3
+ class Calc
4
+
5
+ # 计算不同币别的价格
6
+ ## @param [Int] total_amount 原始金额
7
+ ## @param [String] currency_code 币别
8
+ ## @param [Int] tax_flag 是否含税
9
+ ## @return [Int] 金额 2000
10
+ ## @author luojie
11
+ ## @date 2021-09-22
12
+ def self.total_amount_by_currency(total_amount, currency_code, tax_flag)
13
+ total_amount = total_amount.to_f
14
+ case currency_code
15
+ when 'PRE007'
16
+ # 美元
17
+ total_amount = total_amount * 6.8
18
+ when 'PRE003'
19
+ # 欧元
20
+ total_amount = total_amount * 8
21
+ else
22
+ end
23
+ total_amount = total_amount/1.13 if tax_flag == 1
24
+ total_amount
25
+ end
26
+
27
+ end
28
+ end
@@ -2,17 +2,18 @@ require 'cgi'
2
2
  require 'oj'
3
3
  module YolCommon
4
4
 
5
- def test(name)
6
- name
7
- end
8
-
9
5
  # 重复范围: 支持日期/数字等所有格式
6
+ ## @param [Array] 数组 [1..20, 5..25]
7
+ ## @return [Array] 数组 [5..20]
8
+ ## @author luojie
9
+ ## @date 2021-03-30
10
10
  def duplicate_periods(periods)
11
+ # periods
11
12
  duplicate_periods = []
12
- periods.each do |a|
13
+ periods.each do |a|
13
14
  a_index = periods.index(a)
14
15
  temp_periods = periods.clone
15
- temp_periods.delete_at(a_index)
16
+ temp_periods.delete_at(a_index)
16
17
  temp_periods.each do |b|
17
18
  result = a & b
18
19
  duplicate_periods << result if result
@@ -21,7 +22,11 @@ module YolCommon
21
22
  duplicate_periods.uniq
22
23
  end
23
24
 
24
- # 计算量日期间的工作日
25
+ # 计算两日期间的工作日
26
+ ## @param [Date] 日期 Thu, 22 Apr 2021
27
+ ## @return [Int] 天数 5
28
+ ## @author luojie
29
+ ## @date 2021-03-30
25
30
  def business_days_between(date1, date2)
26
31
  business_days = 0
27
32
  date = date2
@@ -2,7 +2,7 @@ require 'uri'
2
2
  module YolCommon
3
3
 
4
4
  MOBILE_REGEX = Regexp.new('palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile|zune')
5
-
5
+
6
6
  class Validator
7
7
 
8
8
  # 手机
@@ -1,3 +1,3 @@
1
1
  module YolCommon
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/yol_common.rb CHANGED
@@ -2,6 +2,7 @@ require "yol_common/version"
2
2
  require "yol_common/helper"
3
3
  require "yol_common/validator"
4
4
  require "yol_common/range"
5
+ require "yol_common/calc"
5
6
 
6
7
 
7
8
  module YolCommon
data/yol_common.gemspec CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "yol_common"
8
8
  spec.version = YolCommon::VERSION
9
9
  spec.authors = ["luojie2019"]
10
- spec.email = ["luojie@yolanda.hk@yeezon.com"]
10
+ spec.email = ["luojie@yolanda.hk"]
11
11
  spec.summary = %q{common helpers}
12
12
  spec.description = %q{private gem}
13
- spec.homepage = "https://github.com/luojie2019/yol_common"
13
+ spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yol_common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - luojie2019
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -68,26 +68,25 @@ dependencies:
68
68
  version: '0'
69
69
  description: private gem
70
70
  email:
71
- - luojie@yolanda.hk@yeezon.com
71
+ - luojie@yolanda.hk
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
- - ".DS_Store"
77
76
  - ".gitignore"
78
77
  - Gemfile
79
78
  - Gemfile.lock
80
79
  - LICENSE
81
80
  - README.md
82
81
  - Rakefile
83
- - lib/.DS_Store
84
82
  - lib/yol_common.rb
83
+ - lib/yol_common/calc.rb
85
84
  - lib/yol_common/helper.rb
86
85
  - lib/yol_common/range.rb
87
86
  - lib/yol_common/validator.rb
88
87
  - lib/yol_common/version.rb
89
88
  - yol_common.gemspec
90
- homepage: https://github.com/luojie2019/yol_common
89
+ homepage: ''
91
90
  licenses:
92
91
  - MIT
93
92
  metadata: {}
data/.DS_Store DELETED
Binary file
data/lib/.DS_Store DELETED
Binary file