mirror of
https://github.com/askn/faker.git
synced 2023-08-10 21:13:01 +03:00
add team & company.logo
This commit is contained in:
@@ -17,5 +17,10 @@ module Faker
|
||||
data = Data["company"]["bs"] as Array(Array(String))
|
||||
Faker.fetch(data.flatten)
|
||||
end
|
||||
|
||||
def self.logo
|
||||
rand_num = Random.rand(13) + 1
|
||||
"https://pigment.github.io/fake-logos/logos/medium/color/#{rand_num}.png"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,34 @@ module Faker
|
||||
[user_name(name), "example." + %w(org com net).shuffle.first].join("@")
|
||||
end
|
||||
|
||||
def self.user_name(name = nil, separators = %w(. _))
|
||||
def self.user_name(specifier = nil, separators = %w(. _))
|
||||
if specifier.is_a? String
|
||||
return specifier.scan(/\w+/).map { |s| s[0] }.shuffle.join(separators.sample).downcase
|
||||
elsif specifier.is_a? Int
|
||||
tries = 0 # Don't try forever in case we get something like 1_000_000.
|
||||
result = ""
|
||||
while (tries < 7)
|
||||
result = user_name(nil, separators)
|
||||
tries += 1
|
||||
unless result.size < specifier
|
||||
break
|
||||
end
|
||||
end
|
||||
until result.size >= specifier
|
||||
result = result * 2
|
||||
end
|
||||
return result
|
||||
elsif specifier.is_a? Range
|
||||
tries = 0
|
||||
result = ""
|
||||
while (tries < 7)
|
||||
result = user_name(specifier.min, separators)
|
||||
tries += 1
|
||||
break if specifier.includes?(result.size)
|
||||
end
|
||||
return result[0...specifier.max]
|
||||
end
|
||||
|
||||
return name.scan(/\w+/).shuffle.map(&.[0]).join(separators.sample).downcase if name
|
||||
[
|
||||
->{ Name.first_name.gsub(/\W/, "").downcase },
|
||||
@@ -51,8 +78,14 @@ module Faker
|
||||
container.map { |n| n.to_s(16) }.join(':')
|
||||
end
|
||||
|
||||
def self.url
|
||||
"http://#{domain_name}/#{user_name}"
|
||||
def self.mac_address(prefix = "")
|
||||
prefix_digits = prefix.split(":").map { |d| d.to_i?(16) ? d.to_i?(16) : 0 }
|
||||
address_digits = (1..(6 - prefix_digits.size)).map { rand(256) }
|
||||
(prefix_digits + address_digits).map { |d| "%02x" % d }.join(":")
|
||||
end
|
||||
|
||||
def self.url(host = domain_name, path = "/#{user_name}")
|
||||
"http://#{host}#{path}"
|
||||
end
|
||||
|
||||
def self.slug(words = nil, glue = nil)
|
||||
|
||||
@@ -22,8 +22,8 @@ module Faker
|
||||
words.shuffle[0, num]
|
||||
end
|
||||
|
||||
def self.sentence(word_count = 4, supplemental = false)
|
||||
words(word_count + rand(6), supplemental).join(" ").capitalize + "."
|
||||
def self.sentence(word_count = 4, supplemental = false, random_words_to_add = 6)
|
||||
words(word_count + rand(random_words_to_add.to_i).to_i, supplemental).join(" ").capitalize + "."
|
||||
end
|
||||
|
||||
def self.sentences(sentence_count = 3, supplemental = false)
|
||||
@@ -34,8 +34,8 @@ module Faker
|
||||
end
|
||||
end
|
||||
|
||||
def self.paragraph(sentence_count = 3, supplemental = false)
|
||||
sentences(sentence_count + rand(3), supplemental).join(" ")
|
||||
def self.paragraph(sentence_count = 3, supplemental = false, random_sentences_to_add = 3)
|
||||
sentences(sentence_count + rand(random_sentences_to_add.to_i).to_i, supplemental).join(" ")
|
||||
end
|
||||
|
||||
def self.paragraphs(paragraph_count = 3, supplemental = false)
|
||||
|
||||
15
src/faker/team.cr
Normal file
15
src/faker/team.cr
Normal file
@@ -0,0 +1,15 @@
|
||||
module Faker
|
||||
class Team
|
||||
def self.name
|
||||
Faker.fetch(Data["team"]["name"])
|
||||
end
|
||||
|
||||
def self.creature
|
||||
Faker.fetch(Data["team"]["creature"])
|
||||
end
|
||||
|
||||
def self.state
|
||||
Faker.fetch(Data["address"]["state"])
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user