-
Notifications
You must be signed in to change notification settings - Fork 0
/
decimals.cr
27 lines (26 loc) · 963 Bytes
/
decimals.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Crowbar::Generator::Decimals < Crowbar::Generator
property? quoted = false
property? float = false
def initialize(mutator, length_limit = (2..6), @quoted = false, @float = false)
super mutator, length_limit
end
def make : String
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, 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
if float?
quoted? ? "\"" + output.to_f.to_s + "\"" : output.to_f.to_s
else
quoted? ? "\"" + output.to_i.to_s + "\"" : output.to_i.to_s
end
end
end