lib/rantly/generator.rb in rantly-0.3.1 vs lib/rantly/generator.rb in rantly-0.3.2
- old
+ new
@@ -20,21 +20,20 @@
end
def value(limit=10,&block)
gen.value(limit,&block)
end
-
+
def gen
self.singleton
end
end
class GuardFailure < RuntimeError
end
class TooManyTries < RuntimeError
-
def initialize(limit,nfailed)
@limit = limit
@nfailed = nfailed
end
@@ -82,11 +81,11 @@
nsuccess += 1
limit -= 1
handler.call(val) if handler
end
end
-
+
attr_accessor :classifiers
def initialize
reset
end
@@ -109,11 +108,11 @@
end
def size
@size || Rantly.default_size
end
-
+
def sized(n,&block)
raise "size needs to be greater than zero" if n < 0
old_size = @size
@size = n
r = self.instance_eval(&block)
@@ -220,22 +219,19 @@
end
h
end
module Chars
-
+
class << self
- ASCII = ""
- (0..127).to_a.each do |i|
- ASCII << i
- end
+ ASCII = (0..127).to_a.each_with_object("") { |i, obj| obj << i }
def of(regexp)
ASCII.scan(regexp).to_a.map! { |char| char[0].ord }
end
end
-
+
ALNUM = Chars.of /[[:alnum:]]/
ALPHA = Chars.of /[[:alpha:]]/
BLANK = Chars.of /[[:blank:]]/
CNTRL = Chars.of /[[:cntrl:]]/
DIGIT = Chars.of /[[:digit:]]/
@@ -245,12 +241,12 @@
PUNCT = Chars.of /[[:punct:]]/
SPACE = Chars.of /[[:space:]]/
UPPER = Chars.of /[[:upper:]]/
XDIGIT = Chars.of /[[:xdigit:]]/
ASCII = Chars.of /./
-
-
+
+
CLASSES = {
:alnum => ALNUM,
:alpha => ALPHA,
:blank => BLANK,
:cntrl => CNTRL,
@@ -262,10 +258,10 @@
:space => SPACE,
:upper => UPPER,
:xdigit => XDIGIT,
:ascii => ASCII,
}
-
+
end
def string(char_class=:print)
chars = case char_class
when Regexp