1
0
mirror of https://github.com/askn/faker.git synced 2023-08-10 21:13:01 +03:00

Update to Crystal 0.19.4

This commit is contained in:
Serdar Dogruyol 2016-10-20 14:29:47 +03:00
parent fb5c4708f7
commit ae84c91f94
8 changed files with 130 additions and 130 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,7 +3,7 @@ require "./faker/*"
module Faker
def self.numerify(number_string)
number_string = number_string as String
number_string = number_string.as String
number_string.sub(/#/) { (rand(9) + 1).to_s }.gsub(/#/) { rand(10).to_s }
end
@ -17,26 +17,26 @@ module Faker
def self.regexify(re)
re = re.source if re.is_a?(Regex)
re.gsub(/^\/?\^?/, "").gsub(/\$?\/?$/, "") # Ditch the anchors
.gsub(/\{(\d+)\}/) { "{#{$1},#{$1}}" }.gsub(/\?/, "{0,1}") # All {2} become {2,2} and ? become {0,1}
.gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) { |match| $1 * (Range.new($2.to_i, $3.to_i)).to_a.sample } # [12]{1,2} becomes [12] or [12][12]
.gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) { |match| $1 * ($2.to_i..$3.to_i).to_a.sample } # (12|34){1,2} becomes (12|34) or (12|34)(12|34)
.gsub(/(\\?.)\{(\d+),(\d+)\}/) { |match| $1 * ($2.to_i..$3.to_i).to_a.sample } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
.gsub(/\((.*?)\)/) { |match| match.gsub(/[\(\)]/, "").split("|").sample } # (this|that) becomes "this" or "that"
.gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w\-\w)/) { |range| ((0...range.size).map { |i| range[i].to_s }).join("").split("-").to_a.sample } } # All A-Z inside of [] become C (or X, or whatever)
.gsub(/\[([^\]]+)\]/) { |match| $1.split("").sample } # All [ABC] become B (or A or C)
.gsub("\\d") { |match| (0..9).to_a.sample }
.gsub("\\w") { |match| (("A".."Z").to_a + (0..9).to_a).sample }
re.gsub(/^\/?\^?/, "").gsub(/\$?\/?$/, "") # Ditch the anchors
.gsub(/\{(\d+)\}/) { "{#{$1},#{$1}}" }.gsub(/\?/, "{0,1}") # All {2} become {2,2} and ? become {0,1}
.gsub(/(\[[^\]]+\])\{(\d+),(\d+)\}/) { |match| $1 * (Range.new($2.to_i, $3.to_i)).to_a.sample } # [12]{1,2} becomes [12] or [12][12]
.gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) { |match| $1 * ($2.to_i..$3.to_i).to_a.sample } # (12|34){1,2} becomes (12|34) or (12|34)(12|34)
.gsub(/(\\?.)\{(\d+),(\d+)\}/) { |match| $1 * ($2.to_i..$3.to_i).to_a.sample } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
.gsub(/\((.*?)\)/) { |match| match.gsub(/[\(\)]/, "").split("|").sample } # (this|that) becomes "this" or "that"
.gsub(/\[([^\]]+)\]/) { |match| match.gsub(/(\w\-\w)/) { |range| ((0...range.size).map { |i| range[i].to_s }).join("").split("-").to_a.sample } } # All A-Z inside of [] become C (or X, or whatever)
.gsub(/\[([^\]]+)\]/) { |match| $1.split("").sample } # All [ABC] become B (or A or C)
.gsub("\\d") { |match| (0..9).to_a.sample }
.gsub("\\w") { |match| (("A".."Z").to_a + (0..9).to_a).sample }
end
def self.fetch(data)
data = data as Array
fetched = data.sample as String
data = data.as Array
fetched = data.sample.as String
if fetched.match(/^\//) && fetched.match(/\/$/) # A regex
fetched = Faker.regexify(fetched)
end
Faker.parse(fetched) as String
Faker.parse(fetched).as String
end
def self.parse(st)

View File

@ -5,7 +5,7 @@ module Faker
end
def self.credit_card_expiry_date
credit_card_expiry_date = Faker.fetch(Data["business"]["credit_card_expiry_dates"]) as String
credit_card_expiry_date = Faker.fetch(Data["business"]["credit_card_expiry_dates"]).as String
Time.parse(credit_card_expiry_date, "%Y-%m-%d")
end

View File

@ -18,12 +18,12 @@ module Faker
end
def self.material
product_name = Data["commerce"]["product_name"] as Hash
product_name = Data["commerce"]["product_name"].as Hash
Faker.fetch(product_name["material"])
end
def self.product_name
product_name = Data["commerce"]["product_name"] as Hash
product_name = Data["commerce"]["product_name"].as Hash
Faker.fetch(product_name["adjective"]) + " " + Faker.fetch(product_name["material"]) + " " + Faker.fetch(product_name["product"])
end

View File

@ -9,12 +9,12 @@ module Faker
end
def self.catch_phrase
data = Data["company"]["buzzwords"] as Array(Array(String))
data = Data["company"]["buzzwords"].as Array(Array(String))
Faker.fetch(data.flatten)
end
def self.bs
data = Data["company"]["bs"] as Array(Array(String))
data = Data["company"]["bs"].as Array(Array(String))
Faker.fetch(data.flatten)
end

View File

@ -1,6 +1,6 @@
module Faker
class Finance
CREDIT_CARD_TYPES = (Data["credit_card"] as Hash).keys
CREDIT_CARD_TYPES = (Data["credit_card"].as(Hash)).keys
def self.credit_card(types : Array = [] of Array(String))
types = CREDIT_CARD_TYPES if types.empty?

View File

@ -11,13 +11,13 @@ module Faker
end
def self.word
words = Data["lorem"]["words"] as Array
words = Data["lorem"]["words"].as Array
Faker.fetch(words)
end
def self.words(num = 3, supplemental = false)
words = Data["lorem"]["words"] as Array(String)
words += (Data["lorem"]["supplemental"] as Array(String)) if supplemental
words = Data["lorem"]["words"].as Array(String)
words += (Data["lorem"]["supplemental"].as Array(String)) if supplemental
words.shuffle[0, num]
end

View File

@ -7,7 +7,7 @@ module Faker
{% end %}
def self.title
title = Data["name"]["title"] as Hash
title = Data["name"]["title"].as Hash
Faker.fetch(title["descriptor"]) + " " + Faker.fetch(title["level"]) + " " + Faker.fetch(title["job"])
end
end