Parent

Randexp::Reducer

Public Class Methods

char(quantity) click to toggle source
    # File lib/randexp/reducer.rb, line 57
57:     def self.char(quantity)
58:       case quantity
59:       when :'?'       then ['', Randgen.char].pick
60:       when :+, :'+?'  then Randgen.word
61:       when :*, :'*?'  then ['', Randgen.word].pick
62:       when Range      then Randgen.word(:length => quantity.pick)
63:       when 1, nil     then Randgen.char
64:       when Integer    then Randgen.word(:length => quantity)
65:       end
66:     end
digit(quantity) click to toggle source
    # File lib/randexp/reducer.rb, line 79
79:     def self.digit(quantity)
80:       case quantity
81:       when :'?'       then ['', Randgen.digit].pick
82:       when :+, :'+?'  then raise "Sorry, \"\\d+\" is too vague, try setting a range: \"\\d{1, 5}\""
83:       when :*, :'*?'  then raise "Sorry, \"\\d*\" is too vague, try setting a range: \"\\d{0, 5}\""
84:       when Range      then quantity.pick.of { Randgen.digit } * ''
85:       when Integer    then quantity.of { Randgen.digit } * ''
86:       when nil        then Randgen.digit
87:       end
88:     end
intersection(cell, quantity) click to toggle source
    # File lib/randexp/reducer.rb, line 35
35:     def self.intersection(cell, quantity)
36:       case quantity
37:       when :'?'       then ['', cell.map {|s| reduce(s)}.pick].pick
38:       when :+, :'+?'  then raise "Sorry, \"((...)|(...))+\" is too vague, try setting a range: \"((...)|(...)){1, 3}\""
39:       when :*, :'*?'  then raise "Sorry, \"((...)|(...))*\" is too vague, try setting a range: \"((...)|(...)){0, 3}\""
40:       when Range      then quantity.pick.of { cell.map {|s| reduce(s)}.pick } * ''
41:       when Integer    then quantity.of { cell.map {|s| reduce(s)}.pick } * ''
42:       when nil        then cell.map {|s| reduce(s)}.pick
43:       end
44:     end
literal(cell, quantity = nil) click to toggle source
    # File lib/randexp/reducer.rb, line 24
24:     def self.literal(cell, quantity = nil)
25:       case quantity
26:       when :'?'         then ([''] + cell).pick
27:       when :+, :'+?'    then raise "Sorry, \"#{cell * ''}+\" is too vague, try setting a range: \"#{cell * ''}{1,3}\""
28:       when :*, :'*?'    then raise "Sorry, \"#{cell * ''}*\" is too vague, try setting a range: \"#{cell * ''}{0,3}\""
29:       when Range        then quantity.pick.of { cell * '' } * ''
30:       when Integer      then quantity.of { cell * '' } * ''
31:       when nil          then cell * ''
32:       end
33:     end
quantify(sexp, old_quantity) click to toggle source
    # File lib/randexp/reducer.rb, line 11
11:     def self.quantify(sexp, old_quantity)
12:       reduce(*sexp)
13:     end
randgen(args, quantity) click to toggle source
     # File lib/randexp/reducer.rb, line 90
 90:     def self.randgen(args, quantity)
 91:       method_name, _ = *args
 92:       case quantity
 93:       when :'?'       then ['', Randgen.send(method_name, :length => 1)].pick
 94:       when :+, :'+?'  then Randgen.send(method_name)
 95:       when :*, :'*?'  then ['', Randgen.send(method_name)].pick
 96:       when Range      then Randgen.send(method_name, :length => quantity.pick)
 97:       when 1, nil     then Randgen.send(method_name)
 98:       when Integer    then Randgen.send(method_name, :length => quantity)
 99:       end
100:     end
random(sexpish, quantity) click to toggle source
    # File lib/randexp/reducer.rb, line 15
15:     def self.random(sexpish, quantity)
16:       case s = sexpish.first
17:       when :w then char(quantity)
18:       when :s then whitespace(quantity)
19:       when :d then digit(quantity)
20:       else randgen(s, quantity)
21:       end
22:     end
reduce(sexp, quantity = nil) click to toggle source
   # File lib/randexp/reducer.rb, line 3
3:     def self.reduce(sexp, quantity = nil)
4:       send(sexp.first, sexp[1..1], quantity)
5:     end
union(cell, quantity) click to toggle source
    # File lib/randexp/reducer.rb, line 46
46:     def self.union(cell, quantity)
47:       case quantity
48:       when :'?'       then ['', cell.map {|s| reduce(s)} * ''].pick
49:       when :+, :'+?'  then raise "Sorry, \"(...)+\" is too vague, try setting a range: \"(...){1, 3}\""
50:       when :*, :'*?'  then raise "Sorry, \"(...)*\" is too vague, try setting a range: \"(...){0, 3}\""
51:       when Range      then quantity.pick.of { cell.map {|s| reduce(s)} * '' } * ''
52:       when Integer    then quantity.of { cell.map {|s| reduce(s)} * '' } * ''
53:       when nil        then cell.map {|s| reduce(s)} * ''
54:       end
55:     end
whitespace(quantity) click to toggle source
    # File lib/randexp/reducer.rb, line 68
68:     def self.whitespace(quantity)
69:       case quantity
70:       when :'?'       then ['', Randgen.whitespace].pick
71:       when :+, :'+?'  then raise "Sorry, \"\\s+\" is too vague, try setting a range: \"\\s{1, 5}\""
72:       when :*, :'*?'  then raise "Sorry, \"\\s*\" is too vague, try setting a range: \"\\s{0, 5}\""
73:       when Range      then quantity.pick.of { Randgen.whitespace } * ''
74:       when Integer    then quantity.of { Randgen.whitespace } * ''
75:       when nil        then Randgen.whitespace
76:       end
77:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.