Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
172 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
class Crowbar::Generator::Decimals < Crowbar::Generator | ||
def initialize(crowbar, length_limit = (0..10)) | ||
super crowbar, length_limit | ||
property? quoted = false | ||
property? float = false | ||
def initialize(mutator, length_limit = (0..10)) | ||
super mutator, length_limit | ||
end | ||
|
||
def make : String | ||
length = self.crowbar.noise.int(self.crowbar.iteration, length_limit.begin, length_limit.end) | ||
length = self.crowbar.noise.int(self.crowbar.iteration, self.length_limit.begin, self.length_limit.end) | ||
output = "" | ||
point = self.crowbar.noise.int(self.crowbar.iteration, iteration, 0, length-1) | ||
length.times do |x| | ||
digit_index = self.crowbar.noise.int(self.crowbar.iteration + x, @iteration, 0, 1000) | ||
digit = Constants::NUMBERS.to_a[digit_index % Constants::NUMBERS.size].to_s | ||
digit_index = self.crowbar.noise.int(self.crowbar.iteration + x, self.iteration, 0, 1000) | ||
digit = Crowbar::Constants::NUMBERS.to_a[digit_index % Crowbar::Constants::NUMBERS.size].to_s | ||
output += digit | ||
if float? && x == point | ||
output += '.' | ||
end | ||
end | ||
@iteration += 1 | ||
output.to_i.to_s | ||
quoted? ? "\"" + output.to_i.to_s + "\"" : output.to_i.to_s | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
class Crowbar::Match | ||
property start = 0 | ||
property finish = 0 | ||
property match = "" | ||
property string = "" | ||
property? matched = false | ||
|
||
def range | ||
(start..finish) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
# Duplicates symbols next to each other | ||
class Crowbar::Mutator::RepeaterDuplicator < Crowbar::Mutator | ||
@regex : Regex = Constants::Regex::SYMBOLS | ||
def initialize(crowbar, @regex = Constants::Regex::SYMBOLS) | ||
super crowbar | ||
end | ||
# # Duplicates symbols next to each other | ||
# class Crowbar::Mutator::Repeater < Crowbar::Mutator | ||
# @regex : Regex = Constants::Regex::SYMBOLS | ||
# def initialize(crowbar, @regex = Constants::Regex::SYMBOLS) | ||
# super crowbar | ||
# end | ||
|
||
def mutate(input) | ||
# detect symbols in text | ||
matches = input.scan(@regex) | ||
# def mutate(input) | ||
# # detect symbols in text | ||
# matches = input.scan(@regex) | ||
|
||
#TODO: FIX THIS FOR MULTI CHAR INSERTS | ||
effect = self.crowbar.noise.height_float(self.crowbar.iteration, self.crowbar.iteration, 1) | ||
index_offset = 0 | ||
output = input | ||
symbols_shuffle = self.crowbar.noise.shuffle(self.crowbar.iteration, matches) | ||
symbols_shuffle[0..(matches.size*effect).to_i].sort{|a,b| a.begin.as(Int32) <=> b.begin.as(Int32)}.each do |match| | ||
output = output.insert(match.begin.as(Int32) + index_offset, match[0]) | ||
index_offset += 1 | ||
end | ||
output | ||
end | ||
end | ||
# #TODO: FIX THIS FOR MULTI CHAR INSERTS | ||
# effect = self.crowbar.noise.height_float(self.crowbar.iteration, self.crowbar.iteration, 1) | ||
# index_offset = 0 | ||
# output = input | ||
# symbols_shuffle = self.crowbar.noise.shuffle(self.crowbar.iteration, matches) | ||
# symbols_shuffle[0..(matches.size*effect).to_i].sort{|a,b| a.begin.as(Int32) <=> b.begin.as(Int32)}.each do |match| | ||
# output = output.insert(match.begin.as(Int32) + index_offset, match[0]) | ||
# index_offset += 1 | ||
# end | ||
# output | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
# Removes symbols | ||
class Crowbar::Mutator::Remover < Crowbar::Mutator | ||
@regex : Regex = Constants::Regex::SYMBOLS | ||
def initialize(crowbar, @regex = Constants::Regex::SYMBOLS) | ||
super crowbar | ||
end | ||
# # Removes symbols | ||
# class Crowbar::Mutator::Remover < Crowbar::Mutator | ||
# @regex : Regex = Constants::Regex::SYMBOLS | ||
# def initialize(crowbar, @regex = Constants::Regex::SYMBOLS) | ||
# super crowbar | ||
# end | ||
|
||
def mutate(input) | ||
# detect symbols in text | ||
matches = [] of Int32 | ||
input.scan(@regex) do |match| | ||
if match.begin | ||
matches << match.begin.as(Int32) | ||
end | ||
end | ||
# def mutate(input) | ||
# # detect symbols in text | ||
# matches = [] of Int32 | ||
# input.scan(@regex) do |match| | ||
# if match.begin | ||
# matches << match.begin.as(Int32) | ||
# end | ||
# end | ||
|
||
# TODO: FIX THIS FOR MULTICHAR DELETES | ||
effect = self.crowbar.noise.height_float(self.crowbar.iteration, self.crowbar.iteration, 1) | ||
index_offset = 0 | ||
output = input | ||
symbols_shuffle = self.crowbar.noise.shuffle(self.crowbar.iteration, matches) | ||
symbols_shuffle[0..(matches.size*effect).to_i].sort.each do |index| | ||
output = output.sub(index + index_offset, "") | ||
index_offset -= 1 | ||
end | ||
output | ||
end | ||
end | ||
# # TODO: FIX THIS FOR MULTICHAR DELETES | ||
# effect = self.crowbar.noise.height_float(self.crowbar.iteration, self.crowbar.iteration, 1) | ||
# index_offset = 0 | ||
# output = input | ||
# symbols_shuffle = self.crowbar.noise.shuffle(self.crowbar.iteration, matches) | ||
# symbols_shuffle[0..(matches.size*effect).to_i].sort.each do |index| | ||
# output = output.sub(index + index_offset, "") | ||
# index_offset -= 1 | ||
# end | ||
# output | ||
# end | ||
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,18 @@ | ||
# Replaces symbols | ||
class Crowbar::Mutator::Replacer < Crowbar::Mutator | ||
@regex : Regex | ||
|
||
def initialize(selector, @regex = Crowbar::Constants::Regex::IN_QUOTES) | ||
def initialize(selector) | ||
super selector do |m| | ||
yield m | ||
end | ||
end | ||
|
||
def mutate(input) : String | ||
# detect symbols in text | ||
matches = input.scan(@regex) | ||
|
||
effect = self.crowbar.noise.height_float(self.crowbar.iteration, self.crowbar.iteration, 1) | ||
shuffled_matches = self.crowbar.noise.shuffle(self.crowbar.iteration, matches) | ||
used_matches = shuffled_matches[0..(matches.size*effect).to_i].sort{|a,b| a.begin.as(Int32) <=> b.begin.as(Int32)} | ||
|
||
offset = 0 | ||
output = input | ||
used_matches.each do |match| | ||
start = match.begin.as(Int32) + offset | ||
finish = match.end.as(Int32) + offset | ||
range = (start...finish) | ||
replacement = @generator.make | ||
output = output.sub(range, replacement) | ||
offset += replacement.size - range.size | ||
def mutate(match : Crowbar::Match) : String | ||
if @generators.size >= 2 | ||
item = crowbar.noise.item(iteration, crowbar.iteration, @generators).make | ||
else | ||
item = @generators[0].make | ||
end | ||
output | ||
@iteration += 1 | ||
item | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
abstract class Crowbar::Selector | ||
getter crowbar : Crowbar | ||
getter mutators = [] of Mutator | ||
getter mutators = [] of Crowbar::Mutator | ||
|
||
getter iteration = 0 | ||
|
||
def initialize(@crowbar) | ||
@crowbar << self | ||
yield self | ||
end | ||
|
||
def << (mutator) | ||
@mutators << mutator | ||
end | ||
|
||
abstract def select(input) : Array(Crowbar::Match) | ||
abstract def matches : Array(Crowbar::Match) | ||
end |
Oops, something went wrong.