faker_zextend 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 837a8b59a5eb2cecfbbeca93a318116e016f47104988a1f9518ad04041644066
4
+ data.tar.gz: 6bfddf621fc25f99501cd74154a3a8b8f0d321be7599f0992f78dcb23b78f696
5
+ SHA512:
6
+ metadata.gz: c3b7b3044197796a0feb63865f06486f431deceb5c6808fec3b03e09eb7dffc3057a89f9c01485e1d028654725020219ae5c97b7cc0a83c434ea144881ff2d2a
7
+ data.tar.gz: 628fb801d398f68444fc70dcd50d802e4c11accc61d8bde7692b69cf83a2f7b0b8f567671eda1f81817b0fa4b540e02dcfd0734694c40a01bcaca89b6dbde17e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in faker_zextend.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ faker_zextend (0.1.0)
5
+ faker
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ concurrent-ruby (1.3.6)
11
+ diff-lcs (1.6.2)
12
+ faker (3.8.0)
13
+ i18n (>= 1.8.11, < 2)
14
+ i18n (1.14.8)
15
+ concurrent-ruby (~> 1.0)
16
+ rake (12.3.3)
17
+ rspec (3.13.2)
18
+ rspec-core (~> 3.13.0)
19
+ rspec-expectations (~> 3.13.0)
20
+ rspec-mocks (~> 3.13.0)
21
+ rspec-core (3.13.6)
22
+ rspec-support (~> 3.13.0)
23
+ rspec-expectations (3.13.5)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.13.0)
26
+ rspec-mocks (3.13.8)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.13.0)
29
+ rspec-support (3.13.7)
30
+
31
+ PLATFORMS
32
+ ruby
33
+ x86_64-linux
34
+
35
+ DEPENDENCIES
36
+ faker_zextend!
37
+ rake (~> 12.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 2.6.9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 saidev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,237 @@
1
+ # FakerZextend
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/faker_zextend.svg)](https://rubygems.org/gems/faker_zextend)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE.txt)
5
+
6
+ A Ruby gem that extends the popular [Faker](https://github.com/faker-ruby/faker) library with **Chinese-specific fake data generators** — valid 18-digit resident ID cards, uniform social credit codes, bank card numbers with Luhn check digits, Chinese zip codes, company names, and mixed Chinese text.
7
+
8
+ > 仓库地址: <https://github.com/bluesaiz/faker_zextend>
9
+
10
+ ## 特性 Features
11
+
12
+ - 18 位中国居民身份证号(含真实校验位算法)
13
+ - 18 位统一社会信用代码(含 9 位组织机构代码 + 加权校验位)
14
+ - 19 位银行卡号(Luhn 算法校验,覆盖 10 家主流银行 BIN)
15
+ - 12 位银行联行号
16
+ - 6 位中国大陆邮政编码
17
+ - 中文公司名(自 CSV 词库随机组合)
18
+ - 混合中文/数字/字母文本,可选特殊符号
19
+
20
+ 所有模块在加载时自动将 `Faker::Config.locale` 设为 `zh-CN`,因此原生 `Faker::Name.name`、`Faker::Address.full_address`、`Faker::PhoneNumber.cell_phone` 等同样返回中文数据。
21
+
22
+ ## 安装 Installation
23
+
24
+ 将下面这行加到你的 `Gemfile` 中:
25
+
26
+ ```ruby
27
+ gem 'faker_zextend'
28
+ ```
29
+
30
+ 然后执行:
31
+
32
+ ```bash
33
+ bundle install
34
+ ```
35
+
36
+ 或直接安装:
37
+
38
+ ```bash
39
+ gem install faker_zextend
40
+ ```
41
+
42
+ ## 快速开始 Quick Start
43
+
44
+ ```ruby
45
+ require 'faker_zextend'
46
+
47
+ Faker::Chinese::IDNumber.id_number # => "14030019600512831X"
48
+ Faker::Chinese::UniSocialCode.uni_social_code # => "91100000X001TEST0A"
49
+ Faker::Chinese::Bank.bank_card_no # => "6230621234567890123"
50
+ Faker::Chinese::Bank.union_code # => "102100000001"
51
+ Faker::Chinese::Zip.zip # => "100089"
52
+ Faker::Chinese::Company.name # => "杭州阿里巴巴网络科技有限公司"
53
+ Faker::Chinese::Text.random_text(20) # => "北京shanghai58XY..."
54
+ Faker::Chinese::Text.random_text_with_special(20)
55
+ ```
56
+
57
+ 由 gem 设置的 `Faker::Config.locale = 'zh-CN'` 会同时作用于原生 Faker:
58
+
59
+ ```ruby
60
+ Faker::Name.name # => "李明"
61
+ Faker::Address.full_address # => "上海市浦东新区张江路 88 号"
62
+ Faker::PhoneNumber.cell_phone # => "13912345678"
63
+ Faker::Internet.email # => "test@example.cn"
64
+ Faker::Internet.url # => "http://www.example.cn"
65
+ ```
66
+
67
+ ## 模块详解 Module Reference
68
+
69
+ ### `Faker::Chinese::IDNumber`
70
+
71
+ 生成符合 GB 11643-1999 标准的 18 位身份证号。
72
+
73
+ ```ruby
74
+ # 完全随机(6 位地区码 + 8 位生日 + 3 位顺序码 + 1 位校验码)
75
+ Faker::Chinese::IDNumber.id_number
76
+ # => "430482199203157218"
77
+
78
+ # 指定地区码(必须是 6 位有效行政区划码)
79
+ Faker::Chinese::IDNumber.id_number("110105")
80
+ # => "11010519880101123X"
81
+ ```
82
+
83
+ 生日范围:1960-01-01 ~ 2020-12-30。校验位使用 ISO 7064:1983 MOD 11-2 权重算法。
84
+
85
+ ### `Faker::Chinese::UniSocialCode`
86
+
87
+ 生成符合 GB 32100-2015 的 18 位统一社会信用代码。
88
+
89
+ ```ruby
90
+ Faker::Chinese::UniSocialCode.uni_social_code
91
+ # => "91100008MA5XYZ1A2K"
92
+ ```
93
+
94
+ 结构:登记管理部门代码 (1) + 机构类别代码 (1) + 行政区划码 (6) + 组织机构代码 (9) + 校验码 (1)。组织机构代码前 8 位从 31 个合法字符随机生成,第 9 位根据加权算法得出。
95
+
96
+ ### `Faker::Chinese::Bank`
97
+
98
+ ```ruby
99
+ # 19 位银行卡号(默认从 10 家银行 BIN 池随机)
100
+ Faker::Chinese::Bank.bank_card_no
101
+ # => "6213431234567890123"
102
+
103
+ # 指定 BIN(6 位)
104
+ Faker::Chinese::Bank.bank_card_no("622848") # 农业银行 BIN
105
+
106
+ # 自定义长度(默认 19)
107
+ Faker::Chinese::Bank.bank_card_no(nil, 16)
108
+
109
+ # 12 位银行联行号
110
+ Faker::Chinese::Bank.union_code
111
+ # => "313100000001"
112
+ ```
113
+
114
+ 支持的银行 BIN:
115
+
116
+ | 银行 | BIN |
117
+ |---|---|
118
+ | 工商银行 | 623062 |
119
+ | 中国银行 | 621343 |
120
+ | 建设银行 | 622676 |
121
+ | 招商银行 | 410062 |
122
+ | 中信银行 | 433680 |
123
+ | 光大银行 | 622663 |
124
+ | 民生银行 | 622622 |
125
+ | 交通银行 | 621335 |
126
+ | 平安银行 | 622989 |
127
+ | 农业银行 | 622848 |
128
+
129
+ 最后一位使用 Luhn 算法校验。
130
+
131
+ ### `Faker::Chinese::Zip`
132
+
133
+ ```ruby
134
+ Faker::Chinese::Zip.zip
135
+ # => "200120"
136
+ ```
137
+
138
+ 从内置的省/市/区三级 `chinese_zip.json` 词库中随机抽取一个真实邮编。
139
+
140
+ ### `Faker::Chinese::Company`
141
+
142
+ ```ruby
143
+ Faker::Chinese::Company.name
144
+ # => "深圳市腾讯计算机系统有限公司"
145
+ ```
146
+
147
+ 名称来自 `company_name.csv` 词库,约 3.8 万条真实公司名样本。
148
+
149
+ ### `Faker::Chinese::Text`
150
+
151
+ ```ruby
152
+ # 长度 len,混合汉字 + 数字 + 字母,比例随机约 3:1:1
153
+ Faker::Chinese::Text.random_text(30)
154
+ # => "上海科技有限公司MX8k上海信息..."
155
+
156
+ # 在 random_text 基础上追加全部特殊符号
157
+ Faker::Chinese::Text.random_text_with_special(30)
158
+ ```
159
+
160
+ 适合在测试中填充备注、地址、描述等中文字段。
161
+
162
+ ## 开发 Development
163
+
164
+ ```bash
165
+ git clone https://github.com/bluesaiz/faker_zextend.git
166
+ cd faker_zextend
167
+ bundle install
168
+ ```
169
+
170
+ ### 运行测试
171
+
172
+ ```bash
173
+ bundle exec rspec
174
+ ```
175
+
176
+ 测试覆盖所有公共方法(ID 号、统一信用代码、银行卡号、联行号、邮编、公司名、随机文本)的长度与基本结构。
177
+
178
+ ### 目录结构
179
+
180
+ ```
181
+ faker_zextend/
182
+ ├── lib/
183
+ │ ├── faker_zextend.rb # 入口:设置 locale + 加载所有 extend
184
+ │ └── faker_zextend/
185
+ │ ├── version.rb
186
+ │ └── extend/
187
+ │ └── chinese/
188
+ │ ├── id_number.rb
189
+ │ ├── uni_social_code.rb
190
+ │ ├── bank_card.rb
191
+ │ ├── zip.rb
192
+ │ ├── company.rb
193
+ │ ├── text.rb
194
+ │ ├── chinese_zip.json # 邮编省/市/区词库
195
+ │ ├── bank_union_code.json # 联行号词库
196
+ │ └── company_name.csv # 公司名词库
197
+ ├── spec/ # RSpec 测试
198
+ ├── faker_zextend.gemspec
199
+ └── README.md
200
+ ```
201
+
202
+ ### 打包
203
+
204
+ ```bash
205
+ rake build
206
+ ```
207
+
208
+ 产物会输出到 `pkg/faker_zextend-<version>.gem`。
209
+
210
+ 发布到 RubyGems:
211
+
212
+ ```bash
213
+ rake release
214
+ ```
215
+
216
+ ## 依赖 Dependencies
217
+
218
+ - Ruby `>= 2.3.0`
219
+ - [faker](https://github.com/faker-ruby/faker) `>= 3.x`
220
+
221
+ ## 贡献 Contributing
222
+
223
+ 1. Fork 仓库
224
+ 2. 创建特性分支 (`git checkout -b feature/awesome-thing`)
225
+ 3. 提交更改 (`git commit -m 'Add awesome thing'`)
226
+ 4. 推送分支 (`git push origin feature/awesome-thing`)
227
+ 5. 创建 Pull Request
228
+
229
+ 欢迎补充新模块:车牌号、ISBN、组织机构代码、营业执照号等。词库更新也欢迎提 PR。
230
+
231
+ ## 许可 License
232
+
233
+ [MIT](./LICENSE.txt) © 2021 saidev
234
+
235
+ ## 仓库 Repository
236
+
237
+ <https://github.com/bluesaiz/faker_zextend>
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "faker_zextend"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ require_relative 'lib/faker_zextend/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "faker_zextend"
5
+ spec.version = FakerZextend::VERSION
6
+ spec.authors = ["saidev"]
7
+ spec.email = ["saidev@163.com"]
8
+
9
+ spec.summary = %q{extend faker for chinese data faker}
10
+ spec.description = %q{extend faker for chinese data faker}
11
+ spec.homepage = "https://github.com/bluesaiz/faker_zextend"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/bluesaiz/faker_zextend"
19
+ spec.metadata["changelog_uri"] = "https://github.com/bluesaiz/faker_zextend"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+ spec.add_dependency 'faker'
30
+ end