faker 1.8.7 → 1.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +146 -6
- data/README.md +44 -4
- data/lib/extensions/array.rb +10 -10
- data/lib/extensions/symbol.rb +0 -1
- data/lib/faker.rb +42 -35
- data/lib/faker/address.rb +39 -13
- data/lib/faker/app.rb +1 -3
- data/lib/faker/appliance.rb +13 -0
- data/lib/faker/avatar.rb +2 -2
- data/lib/faker/bank.rb +72 -15
- data/lib/faker/beer.rb +0 -1
- data/lib/faker/bitcoin.rb +4 -5
- data/lib/faker/bojack_horseman.rb +17 -0
- data/lib/faker/breaking_bad.rb +0 -3
- data/lib/faker/business.rb +1 -2
- data/lib/faker/cannabis.rb +42 -0
- data/lib/faker/chuck_norris.rb +3 -2
- data/lib/faker/code.rb +59 -20
- data/lib/faker/coffee.rb +4 -0
- data/lib/faker/color.rb +2 -2
- data/lib/faker/commerce.rb +3 -4
- data/lib/faker/community.rb +13 -0
- data/lib/faker/company.rb +80 -24
- data/lib/faker/currency.rb +17 -0
- data/lib/faker/date.rb +13 -27
- data/lib/faker/demographic.rb +2 -2
- data/lib/faker/device.rb +29 -0
- data/lib/faker/dota.rb +25 -0
- data/lib/faker/dr_who.rb +7 -8
- data/lib/faker/dumb_and_dumber.rb +1 -1
- data/lib/faker/dune.rb +4 -4
- data/lib/faker/elder_scrolls.rb +16 -0
- data/lib/faker/electrical_components.rb +19 -0
- data/lib/faker/ethereum.rb +12 -0
- data/lib/faker/famous_last_words.rb +11 -0
- data/lib/faker/file.rb +2 -5
- data/lib/faker/fillmurray.rb +3 -4
- data/lib/faker/finance.rb +3 -4
- data/lib/faker/food.rb +21 -1
- data/lib/faker/football.rb +21 -0
- data/lib/faker/gender.rb +13 -0
- data/lib/faker/greek_philosophers.rb +13 -0
- data/lib/faker/hacker.rb +9 -11
- data/lib/faker/harry_potter.rb +4 -0
- data/lib/faker/hipster.rb +12 -4
- data/lib/faker/id_number.rb +24 -9
- data/lib/faker/internet.rb +69 -57
- data/lib/faker/invoice.rb +94 -0
- data/lib/faker/job.rb +10 -3
- data/lib/faker/lebowski.rb +2 -2
- data/lib/faker/lord_of_the_rings.rb +5 -1
- data/lib/faker/lorem.rb +32 -8
- data/lib/faker/lorem_flickr.rb +43 -0
- data/lib/faker/lorem_pixel.rb +20 -5
- data/lib/faker/lovecraft.rb +12 -5
- data/lib/faker/markdown.rb +12 -4
- data/lib/faker/measurement.rb +35 -80
- data/lib/faker/michael_scott.rb +9 -0
- data/lib/faker/military.rb +25 -0
- data/lib/faker/music.rb +13 -1
- data/lib/faker/myst.rb +25 -0
- data/lib/faker/name.rb +22 -8
- data/lib/faker/nation.rb +24 -0
- data/lib/faker/nato_phonetic_alphabet.rb +9 -0
- data/lib/faker/new_girl.rb +13 -0
- data/lib/faker/number.rb +12 -12
- data/lib/faker/omniauth.rb +110 -122
- data/lib/faker/parks_and_rec.rb +13 -0
- data/lib/faker/phone_number.rb +11 -19
- data/lib/faker/placeholdit.rb +11 -2
- data/lib/faker/princess_bride.rb +13 -0
- data/lib/faker/rick_and_morty.rb +1 -1
- data/lib/faker/science.rb +4 -2
- data/lib/faker/seinfeld.rb +1 -1
- data/lib/faker/shakespeare.rb +0 -3
- data/lib/faker/silicon_valley.rb +4 -0
- data/lib/faker/simpsons.rb +3 -8
- data/lib/faker/singular_siegler.rb +9 -0
- data/lib/faker/slack_emoji.rb +0 -2
- data/lib/faker/source.rb +18 -0
- data/lib/faker/space.rb +4 -0
- data/lib/faker/star_trek.rb +2 -2
- data/lib/faker/star_wars.rb +5 -6
- data/lib/faker/stranger_thing.rb +13 -0
- data/lib/faker/string.rb +45 -0
- data/lib/faker/stripe.rb +63 -0
- data/lib/faker/sword_art_online.rb +21 -0
- data/lib/faker/team.rb +4 -1
- data/lib/faker/the_it_crowd.rb +21 -0
- data/lib/faker/time.rb +10 -10
- data/lib/faker/twin_peaks.rb +2 -2
- data/lib/faker/twitter.rb +1 -1
- data/lib/faker/types.rb +36 -40
- data/lib/faker/university.rb +3 -3
- data/lib/faker/vehicle.rb +72 -10
- data/lib/faker/verb.rb +25 -0
- data/lib/faker/version.rb +1 -1
- data/lib/faker/world_cup.rb +25 -0
- data/lib/helpers/char.rb +19 -20
- data/lib/helpers/unique_generator.rb +7 -1
- data/lib/locales/ca-CAT.yml +1 -1
- data/lib/locales/da-DK.yml +1 -0
- data/lib/locales/de-AT.yml +3 -2
- data/lib/locales/de.yml +6 -5
- data/lib/locales/ee.yml +59 -0
- data/lib/locales/en-CA.yml +23 -1
- data/lib/locales/en-GB.yml +1 -0
- data/lib/locales/en-NZ.yml +4 -3
- data/lib/locales/en-US.yml +2 -0
- data/lib/locales/en.yml +2 -2
- data/lib/locales/en/appliance.yml +5 -0
- data/lib/locales/en/bank.yml +274 -59
- data/lib/locales/en/bojack_horseman.yml +6 -0
- data/lib/locales/en/cannabis.yml +12 -0
- data/lib/locales/en/community.yml +33 -0
- data/lib/locales/en/currency.yml +6 -0
- data/lib/locales/en/dessert.yml +3 -3
- data/lib/locales/en/device.yml +7 -0
- data/lib/locales/en/dota.yml +102 -0
- data/lib/locales/en/dr_who.yml +5 -1
- data/lib/locales/en/dumb_and_dumber.yml +1 -1
- data/lib/locales/en/elder_scrolls.yml +8 -5
- data/lib/locales/en/electrical_components.yml +6 -0
- data/lib/locales/en/famous_last_words.yml +4 -0
- data/lib/locales/en/food.yml +6 -3
- data/lib/locales/en/football.yml +7 -0
- data/lib/locales/en/gender.yml +5 -0
- data/lib/locales/en/greek_philosophers.yml +26 -0
- data/lib/locales/en/harry_potter.yml +2 -1
- data/lib/locales/en/invoice.yml +6 -0
- data/lib/locales/en/job.yml +2 -2
- data/lib/locales/en/lord_of_the_rings.yml +1 -0
- data/lib/locales/en/lorem.yml +4 -0
- data/lib/locales/en/michael_scott.yml +45 -0
- data/lib/locales/en/military.yml +8 -0
- data/lib/locales/en/music.yml +29 -1
- data/lib/locales/en/myst.yml +47 -0
- data/lib/locales/en/name.yml +13 -12
- data/lib/locales/en/nation.yml +8 -0
- data/lib/locales/en/nato_phonetic_alphabet.yml +4 -0
- data/lib/locales/en/new_girl.yml +40 -0
- data/lib/locales/en/overwatch.yml +3 -2
- data/lib/locales/en/parks_and_rec.yml +7 -0
- data/lib/locales/en/princess_bride.yml +5 -0
- data/lib/locales/en/programming_language.yml +2 -1
- data/lib/locales/en/science.yml +1 -0
- data/lib/locales/en/silicon_valley.yml +1 -0
- data/lib/locales/en/singular_siegler.yml +37 -0
- data/lib/locales/en/source.yml +16 -0
- data/lib/locales/en/space.yml +2 -1
- data/lib/locales/en/star_wars.yml +10 -0
- data/lib/locales/en/stranger_thing.yml +36 -0
- data/lib/locales/en/stripe.yml +42 -0
- data/lib/locales/en/sword_art_online.yml +334 -0
- data/lib/locales/en/team.yml +1 -1
- data/lib/locales/en/the_it_crowd.yml +155 -0
- data/lib/locales/en/vehicle.yml +24 -0
- data/lib/locales/en/verbs.yml +8 -0
- data/lib/locales/en/world_cup.yml +271 -0
- data/lib/locales/es.yml +6 -1
- data/lib/locales/fi-FI.yml +9 -4
- data/lib/locales/fr-CA.yml +90 -0
- data/lib/locales/fr-CH.yml +73 -0
- data/lib/locales/fr.yml +4 -2
- data/lib/locales/it.yml +1 -1
- data/lib/locales/ja.yml +11 -0
- data/lib/locales/lv.yml +53 -0
- data/lib/locales/nl.yml +1 -1
- data/lib/locales/no.yml +7 -0
- data/lib/locales/pl.yml +1 -0
- data/lib/locales/pt-BR.yml +21 -13
- data/lib/locales/pt.yml +1 -0
- data/lib/locales/sv.yml +4 -4
- data/lib/locales/tr.yml +8 -0
- data/lib/locales/uk.yml +9 -0
- metadata +167 -3
@@ -0,0 +1,94 @@
|
|
1
|
+
module Faker
|
2
|
+
class Invoice < Base
|
3
|
+
flexible :invoice
|
4
|
+
|
5
|
+
class << self
|
6
|
+
# Generate random amount between values with 2 decimals
|
7
|
+
def amount_between(from = 0, to = 0)
|
8
|
+
Faker::Base.rand_in_range(from, to).round(2)
|
9
|
+
end
|
10
|
+
|
11
|
+
# International bank slip reference https://en.wikipedia.org/wiki/Creditor_Reference
|
12
|
+
# ref is optional so that we can create unit tests
|
13
|
+
def creditor_reference(ref = '')
|
14
|
+
ref = reference if ref.empty?
|
15
|
+
|
16
|
+
'RF' + iban_checksum('RF', ref) + ref
|
17
|
+
end
|
18
|
+
|
19
|
+
# Payment references have some rules in certain countries
|
20
|
+
# ref is optional so that we can create unit tests
|
21
|
+
def reference(ref = '')
|
22
|
+
pattern = fetch('invoice.reference.pattern')
|
23
|
+
|
24
|
+
ref = Base.regexify(/#{pattern}/) if ref.empty?
|
25
|
+
|
26
|
+
# If reference contains reserved '#' characters we need to calculate check_digits as well
|
27
|
+
check_digit_match = ref.match(/#+/)
|
28
|
+
if check_digit_match
|
29
|
+
# Get the method for selected language
|
30
|
+
check_digit_method = fetch('invoice.reference.check_digit_method')
|
31
|
+
|
32
|
+
# Calculate the check digit with matching method name
|
33
|
+
# Trim all '#' from the reference before calculating that
|
34
|
+
check_digit = send(check_digit_method, ref.tr('#', ''))
|
35
|
+
|
36
|
+
# Make sure that our check digit is as long as all of the '###' we found
|
37
|
+
check_digit = check_digit.to_s.rjust(check_digit_match[0].length, '0')
|
38
|
+
|
39
|
+
# Replace all of the
|
40
|
+
ref.sub!(check_digit_match[0], check_digit)
|
41
|
+
end
|
42
|
+
|
43
|
+
ref
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Calculates the mandatory checksum in 3rd and 4th characters in IBAN format
|
49
|
+
# source: https://en.wikipedia.org/wiki/International_Bank_Account_Number#Validating_the_IBAN
|
50
|
+
def iban_checksum(country_code, account)
|
51
|
+
# Converts letters to numbers according the iban rules, A=10..Z=35
|
52
|
+
account_to_number = "#{account}#{country_code}00".upcase.chars.map do |d|
|
53
|
+
d =~ /[A-Z]/ ? (d.ord - 55).to_s : d
|
54
|
+
end.join.to_i
|
55
|
+
|
56
|
+
# This is answer to (iban_to_num + checksum) % 97 == 1
|
57
|
+
checksum = (1 - account_to_number) % 97
|
58
|
+
|
59
|
+
# Use leftpad to make the size always to 2
|
60
|
+
checksum.to_s.rjust(2, '0')
|
61
|
+
end
|
62
|
+
|
63
|
+
# 731 Method
|
64
|
+
# Source: https://wiki.xmldation.com/support/fk/finnish_reference_number
|
65
|
+
def method_731(base)
|
66
|
+
weighted_sum = calculate_weighted_sum(base, [7, 3, 1])
|
67
|
+
mod10_remainder(weighted_sum)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Norsk Modulus 10 - KIDMOD10
|
71
|
+
def kidmod10(base)
|
72
|
+
weighted_sum = calculate_weighted_sum(base, [1, 2])
|
73
|
+
mod10_remainder(weighted_sum)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Calculates weigthed sum
|
77
|
+
#
|
78
|
+
# For example with 12345678, [1,2]
|
79
|
+
# Ref.num. 1 2 3 4 5 6 7 8
|
80
|
+
# Multipl. 1 2 1 2 1 2 1 2
|
81
|
+
# Total 1+ 4+ 3+ 8+ 5+1+2+ 7+1+6 = 38
|
82
|
+
def calculate_weighted_sum(base, weight_factors)
|
83
|
+
base.to_s.reverse.each_char.with_index.map do |digit, index|
|
84
|
+
digit.to_i * weight_factors.at(index % weight_factors.length)
|
85
|
+
end.reduce(:+) # reduce(:+) = sum() but with better ruby version support
|
86
|
+
end
|
87
|
+
|
88
|
+
# MOD-10 - remainder
|
89
|
+
def mod10_remainder(number)
|
90
|
+
-number % 10
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
data/lib/faker/job.rb
CHANGED
@@ -3,14 +3,21 @@ module Faker
|
|
3
3
|
flexible :job
|
4
4
|
|
5
5
|
class << self
|
6
|
-
|
7
6
|
def title
|
8
7
|
parse('job.title')
|
9
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
|
10
|
+
def position
|
11
|
+
fetch('job.position')
|
12
|
+
end
|
13
13
|
|
14
|
+
def field
|
15
|
+
fetch('job.field')
|
16
|
+
end
|
17
|
+
|
18
|
+
def key_skill
|
19
|
+
fetch('job.key_skills')
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
data/lib/faker/lebowski.rb
CHANGED
data/lib/faker/lorem.rb
CHANGED
@@ -14,7 +14,7 @@ module Faker
|
|
14
14
|
translate('faker.lorem.words') +
|
15
15
|
(supplemental ? translate('faker.lorem.supplemental') : [])
|
16
16
|
)
|
17
|
-
word_list
|
17
|
+
word_list *= ((resolved_num / word_list.length) + 1)
|
18
18
|
shuffle(word_list)[0, resolved_num]
|
19
19
|
end
|
20
20
|
|
@@ -28,31 +28,55 @@ module Faker
|
|
28
28
|
Array.new(char_count) { sample(CHARACTERS) }.join
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
31
|
+
def multibyte
|
32
|
+
sample('faker.multibyte')
|
33
|
+
end
|
34
|
+
|
35
|
+
def sentence(word_count = 4, supplemental = false, random_words_to_add = 0)
|
36
|
+
words(word_count + rand(random_words_to_add.to_i), supplemental).join(' ').capitalize + locale_period
|
33
37
|
end
|
34
38
|
|
35
39
|
def sentences(sentence_count = 3, supplemental = false)
|
36
40
|
1.upto(resolve(sentence_count)).collect { sentence(3, supplemental) }
|
37
41
|
end
|
38
42
|
|
39
|
-
def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add =
|
40
|
-
sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(
|
43
|
+
def paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 0)
|
44
|
+
sentences(resolve(sentence_count) + rand(random_sentences_to_add.to_i), supplemental).join(locale_space)
|
41
45
|
end
|
42
46
|
|
43
47
|
def paragraphs(paragraph_count = 3, supplemental = false)
|
44
48
|
1.upto(resolve(paragraph_count)).collect { paragraph(3, supplemental) }
|
45
49
|
end
|
46
50
|
|
47
|
-
def
|
48
|
-
|
51
|
+
def paragraph_by_chars(chars = 256, supplemental = false)
|
52
|
+
paragraph = paragraph(3, supplemental)
|
53
|
+
|
54
|
+
paragraph += ' ' + paragraph(3, supplemental) while paragraph.length < chars
|
55
|
+
|
56
|
+
paragraph[0...chars - 1] + '.'
|
57
|
+
end
|
58
|
+
|
59
|
+
def question(word_count = 4, supplemental = false, random_words_to_add = 0)
|
60
|
+
words(word_count + rand(random_words_to_add), supplemental).join(' ').capitalize + locale_question_mark
|
49
61
|
end
|
50
62
|
|
51
63
|
def questions(question_count = 3, supplemental = false)
|
52
64
|
1.upto(resolve(question_count)).collect { question(3, supplemental) }
|
53
65
|
end
|
54
66
|
|
55
|
-
|
67
|
+
private
|
68
|
+
|
69
|
+
def locale_period
|
70
|
+
translate('faker.lorem.punctuation.period') || '.'
|
71
|
+
end
|
72
|
+
|
73
|
+
def locale_space
|
74
|
+
translate('faker.lorem.punctuation.space') || ' '
|
75
|
+
end
|
76
|
+
|
77
|
+
def locale_question_mark
|
78
|
+
translate('faker.lorem.punctuation.question_mark') || '?'
|
79
|
+
end
|
56
80
|
|
57
81
|
# If an array or range is passed, a random value will be selected.
|
58
82
|
# All other values are simply returned.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Faker
|
2
|
+
class LoremFlickr < Base
|
3
|
+
class << self
|
4
|
+
SUPPORTED_COLORIZATIONS = %w[red green blue].freeze
|
5
|
+
|
6
|
+
def image(size = '300x300', search_terms = [], match_all = false)
|
7
|
+
build_url(size, nil, search_terms, match_all)
|
8
|
+
end
|
9
|
+
|
10
|
+
def grayscale_image(size = '300x300', search_terms = ['all'], match_all = false)
|
11
|
+
raise ArgumentError, 'Search terms must be specified for grayscale images' unless search_terms.any?
|
12
|
+
|
13
|
+
build_url(size, 'g', search_terms, match_all)
|
14
|
+
end
|
15
|
+
|
16
|
+
def pixelated_image(size = '300x300', search_terms = ['all'], match_all = false)
|
17
|
+
raise ArgumentError, 'Search terms must be specified for pixelated images' unless search_terms.any?
|
18
|
+
|
19
|
+
build_url(size, 'p', search_terms, match_all)
|
20
|
+
end
|
21
|
+
|
22
|
+
def colorized_image(size = '300x300', color = 'red', search_terms = ['all'], match_all = false)
|
23
|
+
raise ArgumentError, 'Search terms must be specified for colorized images' unless search_terms.any?
|
24
|
+
raise ArgumentError, "Supported colorizations are #{SUPPORTED_COLORIZATIONS.join(', ')}" unless SUPPORTED_COLORIZATIONS.include?(color)
|
25
|
+
|
26
|
+
build_url(size, color, search_terms, match_all)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def build_url(size, format, search_terms, match_all)
|
32
|
+
raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
|
33
|
+
|
34
|
+
url_parts = ['http://loremflickr.com']
|
35
|
+
url_parts << format
|
36
|
+
url_parts += size.split('x')
|
37
|
+
url_parts << search_terms.compact.join(',') if search_terms.any?
|
38
|
+
url_parts << 'all' if match_all
|
39
|
+
url_parts.compact.join('/')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/faker/lorem_pixel.rb
CHANGED
@@ -1,21 +1,36 @@
|
|
1
1
|
module Faker
|
2
2
|
class LoremPixel < Base
|
3
3
|
class << self
|
4
|
-
SUPPORTED_CATEGORIES = %w
|
4
|
+
SUPPORTED_CATEGORIES = %w[abstract
|
5
|
+
animals
|
6
|
+
business
|
7
|
+
cats
|
8
|
+
city
|
9
|
+
food
|
10
|
+
nightlife
|
11
|
+
fashion
|
12
|
+
people
|
13
|
+
nature
|
14
|
+
sports
|
15
|
+
technics
|
16
|
+
transport].freeze
|
5
17
|
|
6
|
-
|
7
|
-
|
18
|
+
# rubocop:disable Metrics/ParameterLists
|
19
|
+
def image(size = '300x300', is_gray = false, category = nil, number = nil, text = nil, secure: true)
|
20
|
+
raise ArgumentError, 'Size should be specified in format 300x300' unless size =~ /^[0-9]+x[0-9]+$/
|
8
21
|
raise ArgumentError, "Supported categories are #{SUPPORTED_CATEGORIES.join(', ')}" unless category.nil? || SUPPORTED_CATEGORIES.include?(category)
|
9
22
|
raise ArgumentError, 'Category required when number is passed' if !number.nil? && category.nil?
|
10
|
-
raise ArgumentError, 'Number must be between 1 and 10' unless number.nil? || (1..10).
|
23
|
+
raise ArgumentError, 'Number must be between 1 and 10' unless number.nil? || (1..10).cover?(number)
|
11
24
|
raise ArgumentError, 'Category and number must be passed when text is passed' if !text.nil? && number.nil? && category.nil?
|
12
25
|
|
13
|
-
url_parts = ['http
|
26
|
+
url_parts = secure ? ['https:/'] : ['http:/']
|
27
|
+
url_parts << ['lorempixel.com']
|
14
28
|
url_parts << 'g' if is_gray
|
15
29
|
url_parts += size.split('x')
|
16
30
|
url_parts += [category, number, text].compact
|
17
31
|
url_parts.join('/')
|
18
32
|
end
|
33
|
+
# rubocop:enable Metrics/ParameterLists
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|
data/lib/faker/lovecraft.rb
CHANGED
@@ -6,7 +6,7 @@ module Faker
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def fhtagn(number_of = 1)
|
9
|
-
number_of
|
9
|
+
Array.new(number_of) { fetch('lovecraft.fhtagn') }.join('. ')
|
10
10
|
end
|
11
11
|
|
12
12
|
def deity
|
@@ -23,20 +23,19 @@ module Faker
|
|
23
23
|
|
24
24
|
def word
|
25
25
|
random_word = sample(translate('faker.lovecraft.words'))
|
26
|
-
random_word
|
26
|
+
random_word =~ /\s/ ? word : random_word
|
27
27
|
end
|
28
28
|
|
29
29
|
def words(num = 3, spaces_allowed = false)
|
30
30
|
resolved_num = resolve(num)
|
31
31
|
word_list = translate('faker.lovecraft.words')
|
32
|
-
word_list
|
32
|
+
word_list *= ((resolved_num / word_list.length) + 1)
|
33
33
|
|
34
34
|
return shuffle(word_list)[0, resolved_num] if spaces_allowed
|
35
35
|
words = shuffle(word_list)[0, resolved_num]
|
36
|
-
words.each_with_index { |w, i| words[i] = word if w
|
36
|
+
words.each_with_index { |w, i| words[i] = word if w =~ /\s/ }
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
39
|
def sentences(sentence_count = 3)
|
41
40
|
[].tap do |sentences|
|
42
41
|
1.upto(resolve(sentence_count)) do
|
@@ -57,6 +56,14 @@ module Faker
|
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
59
|
+
def paragraph_by_chars(chars = 256)
|
60
|
+
paragraph = paragraph(3)
|
61
|
+
|
62
|
+
paragraph += ' ' + paragraph(3) while paragraph.length < chars
|
63
|
+
|
64
|
+
paragraph[0...chars - 1] + '.'
|
65
|
+
end
|
66
|
+
|
60
67
|
private
|
61
68
|
|
62
69
|
# If an array or range is passed, a random value will be selected.
|
data/lib/faker/markdown.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
module Faker
|
2
2
|
class Markdown < Base
|
3
3
|
class << self
|
4
|
-
|
5
4
|
def headers
|
6
5
|
"#{fetch('markdown.headers')} #{Lorem.word.capitalize}"
|
7
6
|
end
|
@@ -20,7 +19,7 @@ module Faker
|
|
20
19
|
|
21
20
|
result = []
|
22
21
|
number.times do |i|
|
23
|
-
result << "#{i
|
22
|
+
result << "#{i}. #{Faker::Lorem.sentence(1)} \n"
|
24
23
|
end
|
25
24
|
result.join('')
|
26
25
|
end
|
@@ -29,7 +28,7 @@ module Faker
|
|
29
28
|
number = rand(1..10)
|
30
29
|
|
31
30
|
result = []
|
32
|
-
number.times do |
|
31
|
+
number.times do |_i|
|
33
32
|
result << "* #{Faker::Lorem.sentence(1)} \n"
|
34
33
|
end
|
35
34
|
result.join('')
|
@@ -56,12 +55,21 @@ module Faker
|
|
56
55
|
send(available_methods[rand(0..available_methods.length - 1)])
|
57
56
|
end
|
58
57
|
|
58
|
+
def sandwich(sentences = 3, repeat = 1)
|
59
|
+
text_block = []
|
60
|
+
text_block << headers
|
61
|
+
repeat.times do
|
62
|
+
text_block << Faker::Lorem.paragraph(sentences)
|
63
|
+
text_block << random
|
64
|
+
end
|
65
|
+
text_block.join("\n")
|
66
|
+
end
|
67
|
+
|
59
68
|
private
|
60
69
|
|
61
70
|
def available_methods
|
62
71
|
Markdown.public_methods(false) - Base.methods
|
63
72
|
end
|
64
|
-
|
65
73
|
end
|
66
74
|
end
|
67
75
|
end
|
data/lib/faker/measurement.rb
CHANGED
@@ -1,105 +1,43 @@
|
|
1
1
|
module Faker
|
2
2
|
class Measurement < Base
|
3
3
|
class << self
|
4
|
-
ALL =
|
5
|
-
NONE =
|
4
|
+
ALL = 'all'.freeze
|
5
|
+
NONE = 'none'.freeze
|
6
6
|
|
7
7
|
def height(amount = rand(10))
|
8
|
-
|
9
|
-
if amount == ALL
|
10
|
-
make_plural(fetch('measurement.height'))
|
11
|
-
elsif amount == NONE
|
12
|
-
fetch('measurement.height')
|
13
|
-
else
|
14
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.height'), amount)}"
|
15
|
-
end
|
8
|
+
define_measurement_locale(amount, 'height')
|
16
9
|
end
|
17
10
|
|
18
11
|
def length(amount = rand(10))
|
19
|
-
|
20
|
-
if amount == ALL
|
21
|
-
make_plural(fetch('measurement.length'))
|
22
|
-
elsif amount == NONE
|
23
|
-
fetch('measurement.length')
|
24
|
-
else
|
25
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.length'), amount)}"
|
26
|
-
end
|
12
|
+
define_measurement_locale(amount, 'length')
|
27
13
|
end
|
28
14
|
|
29
15
|
def volume(amount = rand(10))
|
30
|
-
|
31
|
-
if amount == ALL
|
32
|
-
make_plural(fetch('measurement.volume'))
|
33
|
-
elsif amount == NONE
|
34
|
-
fetch('measurement.volume')
|
35
|
-
else
|
36
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.volume'), amount)}"
|
37
|
-
end
|
16
|
+
define_measurement_locale(amount, 'volume')
|
38
17
|
end
|
39
18
|
|
40
19
|
def weight(amount = rand(10))
|
41
|
-
|
42
|
-
if amount == ALL
|
43
|
-
make_plural(fetch('measurement.weight'))
|
44
|
-
elsif amount == NONE
|
45
|
-
fetch('measurement.weight')
|
46
|
-
else
|
47
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.weight'), amount)}"
|
48
|
-
end
|
20
|
+
define_measurement_locale(amount, 'weight')
|
49
21
|
end
|
50
22
|
|
51
23
|
def metric_height(amount = rand(10))
|
52
|
-
|
53
|
-
if amount == ALL
|
54
|
-
make_plural(fetch('measurement.height'))
|
55
|
-
elsif amount == NONE
|
56
|
-
fetch('measurement.height')
|
57
|
-
else
|
58
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.height'), amount)}"
|
59
|
-
end
|
24
|
+
define_measurement_locale(amount, 'metric_height')
|
60
25
|
end
|
61
26
|
|
62
27
|
def metric_length(amount = rand(10))
|
63
|
-
|
64
|
-
if amount == ALL
|
65
|
-
make_plural(fetch('measurement.length'))
|
66
|
-
elsif amount == NONE
|
67
|
-
fetch('measurement.length')
|
68
|
-
else
|
69
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.length'), amount)}"
|
70
|
-
end
|
28
|
+
define_measurement_locale(amount, 'metric_length')
|
71
29
|
end
|
72
30
|
|
73
31
|
def metric_volume(amount = rand(10))
|
74
|
-
|
75
|
-
if amount == ALL
|
76
|
-
make_plural(fetch('measurement.volume'))
|
77
|
-
elsif amount == NONE
|
78
|
-
fetch('measurement.volume')
|
79
|
-
else
|
80
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.volume'), amount)}"
|
81
|
-
end
|
32
|
+
define_measurement_locale(amount, 'metric_volume')
|
82
33
|
end
|
83
34
|
|
84
35
|
def metric_weight(amount = rand(10))
|
85
|
-
|
86
|
-
if amount == ALL
|
87
|
-
make_plural(fetch('measurement.weight'))
|
88
|
-
elsif amount == NONE
|
89
|
-
fetch('measurement.weight')
|
90
|
-
else
|
91
|
-
"#{amount.to_s} #{check_for_plural(fetch('measurement.weight'), amount)}"
|
92
|
-
end
|
36
|
+
define_measurement_locale(amount, 'metric_weight')
|
93
37
|
end
|
94
38
|
|
95
39
|
private
|
96
40
|
|
97
|
-
def ensure_valid_amount(amount)
|
98
|
-
unless amount == NONE || amount == ALL || amount.is_a?(Integer) || amount.is_a?(Float)
|
99
|
-
raise ArgumentError, 'invalid amount'
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
41
|
def check_for_plural(text, number)
|
104
42
|
if number && number != 1
|
105
43
|
make_plural(text)
|
@@ -108,16 +46,33 @@ module Faker
|
|
108
46
|
end
|
109
47
|
end
|
110
48
|
|
49
|
+
def define_measurement_locale(amount, locale)
|
50
|
+
ensure_valid_amount(amount)
|
51
|
+
if amount == ALL
|
52
|
+
make_plural(fetch("measurement.#{locale}"))
|
53
|
+
elsif amount == NONE
|
54
|
+
fetch("measurement.#{locale}")
|
55
|
+
else
|
56
|
+
locale = check_for_plural(fetch("measurement.#{locale}"), amount)
|
57
|
+
|
58
|
+
"#{amount} #{locale}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def ensure_valid_amount(amount)
|
63
|
+
raise ArgumentError, 'invalid amount' unless amount == NONE || amount == ALL || amount.is_a?(Integer) || amount.is_a?(Float)
|
64
|
+
end
|
65
|
+
|
111
66
|
def make_plural(text)
|
112
67
|
case text
|
113
|
-
when
|
114
|
-
|
115
|
-
when
|
116
|
-
|
117
|
-
when
|
118
|
-
|
119
|
-
when
|
120
|
-
|
68
|
+
when 'foot'
|
69
|
+
'feet'
|
70
|
+
when 'inch'
|
71
|
+
'inches'
|
72
|
+
when 'fluid ounce'
|
73
|
+
'fluid ounces'
|
74
|
+
when 'metric ton'
|
75
|
+
'metric tons'
|
121
76
|
else
|
122
77
|
"#{text}s"
|
123
78
|
end
|