Run crystal tool format

This commit is contained in:
Ricky Chilcott 2018-09-21 08:13:42 -04:00
parent 4176ac1e5d
commit ed11040aa5
1 changed files with 10 additions and 10 deletions

View File

@ -23,16 +23,16 @@ 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(@@rng) } # [12]{1,2} becomes [12] or [12][12]
.gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) { |match| $1 * ($2.to_i..$3.to_i).to_a.sample(@@rng) } # (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(@@rng) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
.gsub(/\((.*?)\)/) { |match| match.gsub(/[\(\)]/, "").split("|").sample(@@rng) } # (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(@@rng) } } # All A-Z inside of [] become C (or X, or whatever)
.gsub(/\[([^\]]+)\]/) { |match| $1.split("").sample(@@rng) } # All [ABC] become B (or A or C)
.gsub("\\d") { |match| (0..9).to_a.sample(@@rng) }
.gsub("\\w") { |match| (("A".."Z").to_a + (0..9).to_a).sample(@@rng) }
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(@@rng) } # [12]{1,2} becomes [12] or [12][12]
.gsub(/(\([^\)]+\))\{(\d+),(\d+)\}/) { |match| $1 * ($2.to_i..$3.to_i).to_a.sample(@@rng) } # (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(@@rng) } # A{1,2} becomes A or AA or \d{3} becomes \d\d\d
.gsub(/\((.*?)\)/) { |match| match.gsub(/[\(\)]/, "").split("|").sample(@@rng) } # (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(@@rng) } } # All A-Z inside of [] become C (or X, or whatever)
.gsub(/\[([^\]]+)\]/) { |match| $1.split("").sample(@@rng) } # All [ABC] become B (or A or C)
.gsub("\\d") { |match| (0..9).to_a.sample(@@rng) }
.gsub("\\w") { |match| (("A".."Z").to_a + (0..9).to_a).sample(@@rng) }
end
def self.fetch(data)