faker 2.1.0 → 2.2.2
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 +4 -4
- data/CHANGELOG.md +93 -3
- data/README.md +3 -3
- data/lib/faker.rb +56 -1
- data/lib/faker/blockchain/tezos.rb +6 -6
- data/lib/faker/books/dune.rb +10 -2
- data/lib/faker/books/lovecraft.rb +38 -7
- data/lib/faker/default/address.rb +25 -5
- data/lib/faker/default/alphanumeric.rb +39 -7
- data/lib/faker/default/app.rb +9 -1
- data/lib/faker/default/avatar.rb +11 -1
- data/lib/faker/default/bank.rb +10 -2
- data/lib/faker/default/boolean.rb +5 -1
- data/lib/faker/default/chile_rut.rb +12 -2
- data/lib/faker/default/code.rb +16 -3
- data/lib/faker/default/commerce.rb +17 -3
- data/lib/faker/default/company.rb +10 -2
- data/lib/faker/default/crypto_coin.rb +15 -3
- data/lib/faker/default/date.rb +37 -5
- data/lib/faker/default/demographic.rb +5 -1
- data/lib/faker/default/driving_licence.rb +10 -4
- data/lib/faker/default/file.rb +19 -2
- data/lib/faker/default/fillmurray.rb +9 -1
- data/lib/faker/default/finance.rb +5 -1
- data/lib/faker/default/hipster.rb +45 -6
- data/lib/faker/default/id_number.rb +48 -3
- data/lib/faker/default/internet.rb +89 -13
- data/lib/faker/default/invoice.rb +16 -3
- data/lib/faker/default/json.rb +19 -2
- data/lib/faker/default/lorem.rb +80 -10
- data/lib/faker/default/lorem_flickr.rb +38 -5
- data/lib/faker/default/lorem_pixel.rb +10 -1
- data/lib/faker/default/markdown.rb +6 -1
- data/lib/faker/default/measurement.rb +40 -8
- data/lib/faker/default/name.rb +5 -1
- data/lib/faker/default/nhs.rb +5 -1
- data/lib/faker/default/number.rb +56 -11
- data/lib/faker/default/omniauth.rb +50 -9
- data/lib/faker/default/phone_number.rb +5 -1
- data/lib/faker/default/placeholdit.rb +11 -1
- data/lib/faker/default/relationship.rb +5 -1
- data/lib/faker/default/source.rb +18 -3
- data/lib/faker/default/string.rb +5 -1
- data/lib/faker/default/stripe.rb +20 -4
- data/lib/faker/default/time.rb +37 -4
- data/lib/faker/default/twitter.rb +32 -18
- data/lib/faker/default/types.rb +27 -5
- data/lib/faker/default/vehicle.rb +17 -4
- data/lib/faker/default/world_cup.rb +11 -2
- data/lib/faker/games/dota.rb +5 -1
- data/lib/faker/movies/star_wars.rb +6 -4
- data/lib/faker/version.rb +1 -1
- data/lib/locales/en.yml +0 -49
- data/lib/locales/en/science.yml +1 -1
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c140b70507d530616f9c4ab8253cde32bab8bd7489eec025ebc3e0d81027e0be
|
4
|
+
data.tar.gz: b752dafd7f9a6816b811e7b886b0097389fb12f2bb4ff714babcab5215c1528b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01f9d799d52e5b502b21ba569a046f078c45d59e8f0c82e09fa5f79b13bcbf0633a2150d2017623c6ad50256536e94273fc30b59c1835fca639ca4772cf85839
|
7
|
+
data.tar.gz: 4f0fc396d99449791e7edf1ff9013842617e6ecd4c8d153574a773b81041801750c02fb3974c6e05cdfc4429c26bc54528e00a509fa0b8dfd3d788fc5ff0e335
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,101 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v2.
|
3
|
+
## [v2.2.2](https://github.com/faker-ruby/faker/tree/v2.2.2) (2019-05-09)
|
4
4
|
|
5
5
|
## Bug/Fixes
|
6
|
-
|
6
|
+
|
7
|
+
- [PR #1717](https://github.com/faker-ruby/faker/pull/1717) Fix ambiguity in element_symbol field [@psibi](https://github.com/psibi)
|
8
|
+
|
9
|
+
## Chores
|
10
|
+
|
11
|
+
- [PR #1724](https://github.com/faker-ruby/faker/pull/1724) Include rubocop-faker autocorrect in deprecation [@koic](https://github.com/koic)
|
12
|
+
|
13
|
+
## Documentation
|
14
|
+
|
15
|
+
- [PR #1726](https://github.com/faker-ruby/faker/pull/1726) Include 2.x breaking return value change in changelog [@zorab47](https://github.com/zorab47)
|
16
|
+
- [PR #1722](https://github.com/faker-ruby/faker/pull/1722) Fix examples in the Dota docs [@bzf](https://github.com/bzf)
|
17
|
+
|
18
|
+
## Update local dependencies
|
19
|
+
|
20
|
+
The following development dependencies were updated:
|
21
|
+
- rake requirement from = 12.3.1 to = 12.3.3 (#1719)
|
22
|
+
- rubocop requirement from = 0.59.1 to = 0.74.0 (#1721)
|
23
|
+
- simplecov requirement from = 0.16.1 to = 0.17.0 (#1718)
|
24
|
+
|
25
|
+
------------------------------------------------------------------------------
|
26
|
+
|
27
|
+
## [v2.2.1](https://github.com/faker-ruby/faker/tree/v2.2.1) (2019-30-08)
|
28
|
+
|
29
|
+
## Bug/Fixes
|
30
|
+
|
31
|
+
- [PR #1712](https://github.com/faker-ruby/faker/pull/1712) Fix number(digits: 1) always returns 0 [@ianlet](https://github.com/ianlet)
|
32
|
+
|
33
|
+
`Faker::Number.number(digits: 1)` was always returning `0`.
|
34
|
+
|
35
|
+
Fixing number with one digit caused the test_insignificant_zero to fail. As it seemed that the behavior tested by test_insignificant_zero was already covered by test_number and test_decimal, we removed it to prevent duplication.
|
36
|
+
|
37
|
+
## [v2.2.0](https://github.com/faker-ruby/faker/tree/v2.2.0) (2019-25-08)
|
38
|
+
|
39
|
+
## Deprecate
|
40
|
+
|
41
|
+
- [PR #1698](https://github.com/faker-ruby/faker/pull/1698) Add warn for positional arguments when using Faker 2.0 [@koic](https://github.com/koic)
|
42
|
+
|
43
|
+
Add deprecation warning for positional arguments to notify users that are coming from Faker version < 2.0. Its main goal is to make upgrades easier.
|
44
|
+
|
45
|
+
## Documentation
|
46
|
+
|
47
|
+
- [PR #1688](https://github.com/faker-ruby/faker/pull/1688) Update README install instructions [@EduardoGHdez](https://github.com/EduardoGHdez)
|
48
|
+
- [PR #1689](https://github.com/faker-ruby/faker/pull/1689) Update README.md [@Zeragamba](https://github.com/Zeragamba)
|
49
|
+
- [PR #1690](https://github.com/faker-ruby/faker/pull/1690) Update issue url in PULL_REQUEST_TEMPLATE [@bugtender](https://github.com/bugtender)
|
50
|
+
- [PR #1703](https://github.com/faker-ruby/faker/pull/1703) Return HTTPS URLs from Lorem Flickr [@connorshea](https://github.com/connorshea)
|
51
|
+
|
52
|
+
## Feature Request
|
53
|
+
- [PR #1686](https://github.com/faker-ruby/faker/pull/1686) Update test-unit gem to 3.3.3 [@connorshea](https://github.com/connorshea)
|
54
|
+
|
55
|
+
## Bug/Fixes
|
56
|
+
- [PR #1702](https://github.com/faker-ruby/faker/pull/1702) Fix an argument for test_faker_stripe.rb [@koic](https://github.com/koic)
|
57
|
+
- [PR #1694](https://github.com/faker-ruby/faker/pull/1694) Ensure mix_case returns at least one lower and one upper case letter [@bpleslie](https://github.com/bpleslie)
|
58
|
+
|
59
|
+
------------------------------------------------------------------------------
|
60
|
+
|
61
|
+
## [v2.1.2](https://github.com/faker-ruby/faker/tree/v2.1.2) (2019-10-08)
|
62
|
+
|
63
|
+
## Enhancements
|
64
|
+
|
65
|
+
- [PR #1495](https://github.com/faker-ruby/faker/pull/1495) Add Brazilian documents generation and documentation [@lucasqueiroz](https://github.com/lucasqueiroz)
|
66
|
+
|
67
|
+
## Issues
|
68
|
+
|
69
|
+
We had to use `bundled with 1.7.3` to avoid some issues.
|
70
|
+
|
71
|
+
## [v2.1.1](https://github.com/faker-ruby/faker/tree/2.1.1) (2019-10-08)
|
72
|
+
|
73
|
+
## Bug/Fixes
|
74
|
+
|
75
|
+
- [PR #1685](https://github.com/stympy/faker/pull/1685) Upgrade i18n [@EduardoGHdez](https://github.com/EduardoGHdez)
|
76
|
+
|
77
|
+
`bundler-audit` has identified that i18 has fix a security vulnerability, that has been fixed in the 0.8 version.
|
78
|
+
|
79
|
+
- [PR #1683](https://github.com/stympy/faker/pull/1683) Rollback Faker::Time changes [@vbrazo](https://github.com/vbrazo)
|
80
|
+
|
81
|
+
Rollback Faker::Time changes because we should expect the date format from activesupport's en.yml.
|
82
|
+
|
83
|
+
## Documentation
|
84
|
+
|
85
|
+
- [PR #1677](https://github.com/faker-ruby/faker/pull/1677) Fix docs for Internet#password generator [@ur5us](https://github.com/ur5us)
|
86
|
+
|
87
|
+
------------------------------------------------------------------------------
|
88
|
+
|
89
|
+
## [v2.1.0](https://github.com/faker-ruby/faker/tree/v2.1.0) (2019-31-07)
|
90
|
+
|
91
|
+
## Bug/Fixes
|
92
|
+
- [PR #1675](https://github.com/faker-ruby/faker/pull/1675) Fix off-by-one error when formatting month names [@jutonz](https://github.com/jutonz)
|
7
93
|
|
8
94
|
This change required a quick release because it's a breaking issue. Every place where I18n.l() was used began to display the wrong date, causing test suite to fail.
|
9
95
|
|
10
96
|
------------------------------------------------------------------------------
|
11
97
|
|
12
|
-
## [v2.0](https://github.com/
|
98
|
+
## [v2.0](https://github.com/faker-ruby/faker/tree/v2.0) (2019-31-07)
|
13
99
|
|
14
100
|
## Important Note:
|
15
101
|
|
@@ -140,6 +226,10 @@ Version 2 has several `breaking changes`. We replaced positional arguments with
|
|
140
226
|
- `Faker::WorldCup.roster(country = nil, type = nil)` becomes `Faker::WorldCup.roster(country: nil, type: nil)`
|
141
227
|
- `Faker::Movies::StarWars.quote(character = nil)` becomes `Faker::Movies::StarWars.quote(character: nil)`
|
142
228
|
|
229
|
+
Additionally the following methods changed return values:
|
230
|
+
|
231
|
+
- `Faker::Number.number` now returns `Numeric` instead of `String` (see [PR #510](https://github.com/faker-ruby/faker/pull/510))
|
232
|
+
|
143
233
|
### Bug/Fixes
|
144
234
|
|
145
235
|
- [PR #1660](https://github.com/stympy/faker/pull/1660) Update FillMurray Links To Include www [@RaymondFallon](https://github.com/RaymondFallon)
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|

|
3
3
|
|
4
4
|
# Faker
|
5
|
-
[](https://travis-ci.org/faker-ruby/faker)
|
6
6
|
[](https://badge.fury.io/rb/faker)
|
7
7
|
[](http://inch-ci.org/github/stympy/faker)
|
8
8
|
[](https://codeclimate.com/github/stympy/faker/test_coverage)
|
@@ -55,7 +55,7 @@ gem install faker
|
|
55
55
|
Note: if you are getting a `uninitialized constant Faker::[some_class]` error, your version of the gem is behind the one documented here. To make sure that your gem is the one documented here, change the line in your Gemfile to:
|
56
56
|
|
57
57
|
```ruby
|
58
|
-
gem 'faker', :git => 'https://github.com/
|
58
|
+
gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
|
59
59
|
```
|
60
60
|
|
61
61
|
## Usage
|
@@ -117,7 +117,7 @@ Faker::Company.bs #=> "cultivate viral synergies"
|
|
117
117
|
**NOTE: Some of the generators below aren't released yet. If you want to use them, change the line in your gemfile to:**
|
118
118
|
|
119
119
|
```ruby
|
120
|
-
gem 'faker', :git => 'https://github.com/
|
120
|
+
gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'master'
|
121
121
|
```
|
122
122
|
|
123
123
|
### Default
|
data/lib/faker.rb
CHANGED
@@ -40,9 +40,12 @@ module Faker
|
|
40
40
|
class Base
|
41
41
|
Numbers = Array(0..9)
|
42
42
|
ULetters = Array('A'..'Z')
|
43
|
-
|
43
|
+
LLetters = Array('a'..'z')
|
44
|
+
Letters = ULetters + LLetters
|
44
45
|
|
45
46
|
class << self
|
47
|
+
NOT_GIVEN = Object.new
|
48
|
+
|
46
49
|
## by default numerify results do not start with a zero
|
47
50
|
def numerify(number_string, leading_zero: false)
|
48
51
|
return number_string.gsub(/#/) { rand(10).to_s } if leading_zero
|
@@ -245,6 +248,58 @@ module Faker
|
|
245
248
|
ensure
|
246
249
|
I18n.enforce_available_locales = old_enforce_available_locales
|
247
250
|
end
|
251
|
+
|
252
|
+
private
|
253
|
+
|
254
|
+
def warn_for_deprecated_arguments
|
255
|
+
keywords = []
|
256
|
+
yield(keywords)
|
257
|
+
|
258
|
+
return if keywords.empty?
|
259
|
+
|
260
|
+
method_name = caller.first.match(/`(?<method_name>.*)'/)[:method_name]
|
261
|
+
|
262
|
+
keywords.each.with_index(1) do |keyword, index|
|
263
|
+
i = case index
|
264
|
+
when 1 then '1st'
|
265
|
+
when 2 then '2nd'
|
266
|
+
when 3 then '3rd'
|
267
|
+
else "#{index}th"
|
268
|
+
end
|
269
|
+
|
270
|
+
warn_with_uplevel(<<~MSG, uplevel: 5)
|
271
|
+
Passing `#{keyword}` with the #{i} argument of `#{method_name}` is deprecated. Use keyword argument like `#{method_name}(#{keyword}: ...)` instead.
|
272
|
+
MSG
|
273
|
+
end
|
274
|
+
|
275
|
+
warn(<<~MSG)
|
276
|
+
|
277
|
+
To automatically update from positional arguments to keyword arguments,
|
278
|
+
install rubocop-faker and run:
|
279
|
+
|
280
|
+
rubocop \\
|
281
|
+
--require rubocop-faker \\
|
282
|
+
--only Faker/DeprecatedArguments \\
|
283
|
+
--auto-correct
|
284
|
+
|
285
|
+
MSG
|
286
|
+
end
|
287
|
+
|
288
|
+
# Workaround for emulating `warn '...', uplevel: 1` in Ruby 2.4 or lower.
|
289
|
+
def warn_with_uplevel(message, uplevel: 1)
|
290
|
+
at = parse_caller(caller[uplevel]).join(':')
|
291
|
+
warn "#{at}: #{message}"
|
292
|
+
end
|
293
|
+
|
294
|
+
def parse_caller(at)
|
295
|
+
# rubocop:disable Style/GuardClause
|
296
|
+
if /^(.+?):(\d+)(?::in `.*')?/ =~ at
|
297
|
+
file = Regexp.last_match(1)
|
298
|
+
line = Regexp.last_match(2).to_i
|
299
|
+
[file, line]
|
300
|
+
end
|
301
|
+
# rubocop:enable Style/GuardClause
|
302
|
+
end
|
248
303
|
end
|
249
304
|
end
|
250
305
|
end
|
@@ -8,13 +8,13 @@ module Faker
|
|
8
8
|
class Tezos < Base
|
9
9
|
class << self
|
10
10
|
PREFIXES = {
|
11
|
-
tz1:
|
12
|
-
KT1:
|
13
|
-
edpk:
|
14
|
-
edsk:
|
11
|
+
tz1: [6, 161, 159],
|
12
|
+
KT1: [2, 90, 121],
|
13
|
+
edpk: [13, 15, 37, 217],
|
14
|
+
edsk: [13, 15, 58, 7],
|
15
15
|
edsig: [9, 245, 205, 134, 18],
|
16
|
-
B:
|
17
|
-
o:
|
16
|
+
B: [1, 52],
|
17
|
+
o: [5, 116]
|
18
18
|
}.freeze
|
19
19
|
|
20
20
|
def account
|
data/lib/faker/books/dune.rb
CHANGED
@@ -19,7 +19,11 @@ module Faker
|
|
19
19
|
fetch('dune.planets')
|
20
20
|
end
|
21
21
|
|
22
|
-
def quote(character: nil)
|
22
|
+
def quote(legacy_character = NOT_GIVEN, character: nil)
|
23
|
+
warn_for_deprecated_arguments do |keywords|
|
24
|
+
keywords << :character if legacy_character != NOT_GIVEN
|
25
|
+
end
|
26
|
+
|
23
27
|
quoted_characters = translate('faker.dune.quotes').keys
|
24
28
|
|
25
29
|
if character.nil?
|
@@ -36,7 +40,11 @@ module Faker
|
|
36
40
|
fetch('dune.quotes.' + character)
|
37
41
|
end
|
38
42
|
|
39
|
-
def saying(source: nil)
|
43
|
+
def saying(legacy_source = NOT_GIVEN, source: nil)
|
44
|
+
warn_for_deprecated_arguments do |keywords|
|
45
|
+
keywords << :source if legacy_source != NOT_GIVEN
|
46
|
+
end
|
47
|
+
|
40
48
|
sourced_sayings = translate('faker.dune.sayings').keys
|
41
49
|
|
42
50
|
if source.nil?
|
@@ -8,7 +8,11 @@ module Faker
|
|
8
8
|
fetch('lovecraft.location')
|
9
9
|
end
|
10
10
|
|
11
|
-
def fhtagn(number: 1)
|
11
|
+
def fhtagn(legacy_number = NOT_GIVEN, number: 1)
|
12
|
+
warn_for_deprecated_arguments do |keywords|
|
13
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
14
|
+
end
|
15
|
+
|
12
16
|
Array.new(number) { fetch('lovecraft.fhtagn') }.join('. ')
|
13
17
|
end
|
14
18
|
|
@@ -20,7 +24,12 @@ module Faker
|
|
20
24
|
fetch('lovecraft.tome')
|
21
25
|
end
|
22
26
|
|
23
|
-
def sentence(word_count: 4, random_words_to_add: 6)
|
27
|
+
def sentence(legacy_word_count = NOT_GIVEN, legacy_random_words_to_add = NOT_GIVEN, word_count: 4, random_words_to_add: 6)
|
28
|
+
warn_for_deprecated_arguments do |keywords|
|
29
|
+
keywords << :word_count if legacy_word_count != NOT_GIVEN
|
30
|
+
keywords << :random_words_to_add if legacy_random_words_to_add != NOT_GIVEN
|
31
|
+
end
|
32
|
+
|
24
33
|
words(number: word_count + rand(random_words_to_add.to_i).to_i, spaces_allowed: true).join(' ').capitalize + '.'
|
25
34
|
end
|
26
35
|
|
@@ -29,7 +38,12 @@ module Faker
|
|
29
38
|
random_word =~ /\s/ ? word : random_word
|
30
39
|
end
|
31
40
|
|
32
|
-
def words(number: 3, spaces_allowed: false)
|
41
|
+
def words(legacy_number = NOT_GIVEN, legacy_spaces_allowed = NOT_GIVEN, number: 3, spaces_allowed: false)
|
42
|
+
warn_for_deprecated_arguments do |keywords|
|
43
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
44
|
+
keywords << :spaces_allowed if legacy_spaces_allowed != NOT_GIVEN
|
45
|
+
end
|
46
|
+
|
33
47
|
resolved_num = resolve(number)
|
34
48
|
word_list = translate('faker.lovecraft.words')
|
35
49
|
word_list *= ((resolved_num / word_list.length) + 1)
|
@@ -40,7 +54,11 @@ module Faker
|
|
40
54
|
words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
|
41
55
|
end
|
42
56
|
|
43
|
-
def sentences(number: 3)
|
57
|
+
def sentences(legacy_number = NOT_GIVEN, number: 3)
|
58
|
+
warn_for_deprecated_arguments do |keywords|
|
59
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
60
|
+
end
|
61
|
+
|
44
62
|
[].tap do |sentences|
|
45
63
|
1.upto(resolve(number)) do
|
46
64
|
sentences << sentence(word_count: 3)
|
@@ -48,11 +66,20 @@ module Faker
|
|
48
66
|
end
|
49
67
|
end
|
50
68
|
|
51
|
-
def paragraph(sentence_count: 3, random_sentences_to_add: 3)
|
69
|
+
def paragraph(legacy_sentence_count = NOT_GIVEN, legacy_random_sentences_to_add = NOT_GIVEN, sentence_count: 3, random_sentences_to_add: 3)
|
70
|
+
warn_for_deprecated_arguments do |keywords|
|
71
|
+
keywords << :sentence_count if legacy_sentence_count != NOT_GIVEN
|
72
|
+
keywords << :random_sentences_to_add if legacy_random_sentences_to_add != NOT_GIVEN
|
73
|
+
end
|
74
|
+
|
52
75
|
sentences(number: resolve(sentence_count) + rand(random_sentences_to_add.to_i).to_i).join(' ')
|
53
76
|
end
|
54
77
|
|
55
|
-
def paragraphs(number: 3)
|
78
|
+
def paragraphs(legacy_number = NOT_GIVEN, number: 3)
|
79
|
+
warn_for_deprecated_arguments do |keywords|
|
80
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
81
|
+
end
|
82
|
+
|
56
83
|
[].tap do |paragraphs|
|
57
84
|
1.upto(resolve(number)) do
|
58
85
|
paragraphs << paragraph(sentence_count: 3)
|
@@ -60,7 +87,11 @@ module Faker
|
|
60
87
|
end
|
61
88
|
end
|
62
89
|
|
63
|
-
def paragraph_by_chars(characters: 256)
|
90
|
+
def paragraph_by_chars(legacy_characters = NOT_GIVEN, characters: 256)
|
91
|
+
warn_for_deprecated_arguments do |keywords|
|
92
|
+
keywords << :characters if legacy_characters != NOT_GIVEN
|
93
|
+
end
|
94
|
+
|
64
95
|
paragraph = paragraph(sentence_count: 3)
|
65
96
|
|
66
97
|
paragraph += ' ' + paragraph(sentence_count: 3) while paragraph.length < characters
|
@@ -5,7 +5,11 @@ module Faker
|
|
5
5
|
flexible :address
|
6
6
|
|
7
7
|
class << self
|
8
|
-
def city(options: {})
|
8
|
+
def city(legacy_options = NOT_GIVEN, options: {})
|
9
|
+
warn_for_deprecated_arguments do |keywords|
|
10
|
+
keywords << :options if legacy_options != NOT_GIVEN
|
11
|
+
end
|
12
|
+
|
9
13
|
parse(options[:with_state] ? 'address.city_with_state' : 'address.city')
|
10
14
|
end
|
11
15
|
|
@@ -13,7 +17,11 @@ module Faker
|
|
13
17
|
parse('address.street_name')
|
14
18
|
end
|
15
19
|
|
16
|
-
def street_address(include_secondary: false)
|
20
|
+
def street_address(legacy_include_secondary = NOT_GIVEN, include_secondary: false)
|
21
|
+
warn_for_deprecated_arguments do |keywords|
|
22
|
+
keywords << :include_secondary if legacy_include_secondary != NOT_GIVEN
|
23
|
+
end
|
24
|
+
|
17
25
|
numerify(parse('address.street_address') + (include_secondary ? ' ' + secondary_address : ''))
|
18
26
|
end
|
19
27
|
|
@@ -29,7 +37,11 @@ module Faker
|
|
29
37
|
parse('address.community')
|
30
38
|
end
|
31
39
|
|
32
|
-
def zip_code(state_abbreviation: '')
|
40
|
+
def zip_code(legacy_state_abbreviation = NOT_GIVEN, state_abbreviation: '')
|
41
|
+
warn_for_deprecated_arguments do |keywords|
|
42
|
+
keywords << :state_abbreviation if legacy_state_abbreviation != NOT_GIVEN
|
43
|
+
end
|
44
|
+
|
33
45
|
if state_abbreviation.empty?
|
34
46
|
letterified_string = letterify(fetch('address.postcode'))
|
35
47
|
return numerify(letterified_string, leading_zero: true)
|
@@ -71,11 +83,19 @@ module Faker
|
|
71
83
|
fetch('address.country')
|
72
84
|
end
|
73
85
|
|
74
|
-
def country_by_code(code: 'US')
|
86
|
+
def country_by_code(legacy_code = NOT_GIVEN, code: 'US')
|
87
|
+
warn_for_deprecated_arguments do |keywords|
|
88
|
+
keywords << :code if legacy_code != NOT_GIVEN
|
89
|
+
end
|
90
|
+
|
75
91
|
fetch('address.country_by_code.' + code)
|
76
92
|
end
|
77
93
|
|
78
|
-
def country_name_to_code(name: 'united_states')
|
94
|
+
def country_name_to_code(legacy_name = NOT_GIVEN, name: 'united_states')
|
95
|
+
warn_for_deprecated_arguments do |keywords|
|
96
|
+
keywords << :name if legacy_name != NOT_GIVEN
|
97
|
+
end
|
98
|
+
|
79
99
|
fetch('address.country_by_name.' + name)
|
80
100
|
end
|
81
101
|
|
@@ -2,22 +2,54 @@
|
|
2
2
|
|
3
3
|
module Faker
|
4
4
|
class Alphanumeric < Base
|
5
|
-
|
6
|
-
ALPHABET = ('a'..'z').to_a
|
7
|
-
ALPHANUMS = ALPHABET + (0..9).to_a
|
5
|
+
ALPHANUMS = LLetters + Numbers
|
8
6
|
|
9
|
-
|
7
|
+
class << self
|
8
|
+
def alpha(legacy_number = NOT_GIVEN, number: 32)
|
9
|
+
warn_for_deprecated_arguments do |keywords|
|
10
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
11
|
+
end
|
10
12
|
char_count = resolve(number)
|
11
13
|
return '' if char_count.to_i < 1
|
12
14
|
|
13
|
-
Array.new(char_count) { sample(
|
15
|
+
Array.new(char_count) { sample(self::LLetters) }.join
|
14
16
|
end
|
15
17
|
|
16
|
-
|
18
|
+
##
|
19
|
+
# Produces a random string of alphanumeric characters
|
20
|
+
#
|
21
|
+
# @param [Integer] number
|
22
|
+
# @param [Integer] min_alpha
|
23
|
+
# @param [Integer] min_numeric
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
#
|
27
|
+
# @example Faker::Alphanumeric.alphanumeric(number: 10) #=> "3yfq2phxtb"
|
28
|
+
# @example Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3) #=> "3yfq2phxtb"
|
29
|
+
# @example Faker::Alphanumeric.alphanumeric(number: 10, min_alpha: 3, min_numeric: 3) #=> "3yfq2phx8b"
|
30
|
+
#
|
31
|
+
# @faker.version 2.1.3
|
32
|
+
def alphanumeric(legacy_number = NOT_GIVEN, number: 32, min_alpha: 0, min_numeric: 0)
|
33
|
+
warn_for_deprecated_arguments do |keywords|
|
34
|
+
keywords << :number if legacy_number != NOT_GIVEN
|
35
|
+
end
|
17
36
|
char_count = resolve(number)
|
18
37
|
return '' if char_count.to_i < 1
|
38
|
+
raise ArgumentError, 'min_alpha must be greater than or equal to 0' if min_alpha&.negative?
|
39
|
+
raise ArgumentError, 'min_numeric must be greater than or equal to 0' if min_numeric&.negative?
|
40
|
+
|
41
|
+
return Array.new(char_count) { sample(ALPHANUMS) }.join if min_alpha.zero? && min_numeric.zero?
|
42
|
+
|
43
|
+
raise ArgumentError, 'min_alpha + min_numeric must be <= number' if min_alpha + min_numeric > char_count
|
44
|
+
|
45
|
+
random_count = char_count - min_alpha - min_numeric
|
46
|
+
|
47
|
+
alphas = Array.new(min_alpha) { sample(self::LLetters) }
|
48
|
+
numbers = Array.new(min_numeric) { sample(self::Numbers) }
|
49
|
+
randoms = Array.new(random_count) { sample(ALPHANUMS) }
|
19
50
|
|
20
|
-
|
51
|
+
combined = alphas + numbers + randoms
|
52
|
+
combined.shuffle.join
|
21
53
|
end
|
22
54
|
end
|
23
55
|
end
|