Module: RandallInstanceSugar
- Included in:
- Randall
- Defined in:
- lib/randall/sugar.rb
Instance Method Summary collapse
- #close_to(f) ⇒ Object
- #from(type) ⇒ Object
- #greater_than(number) ⇒ Object (also: #gt)
- #in_range(rg) ⇒ Object (also: #between)
- #less_than(number) ⇒ Object (also: #lt)
- #match(re) ⇒ Object
- #of(type) ⇒ Object
- #that ⇒ Object (also: #with, #and)
- #to(type) ⇒ Object
- #with_arguments(*args) ⇒ Object
- #with_size(number) ⇒ Object
Instance Method Details
#close_to(f) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/randall/sugar.rb', line 67 def close_to(f) unless @type == Float then raise ArgumentError, 'Applied to generator for number only.' end @options[:close_to] = f self end |
#from(type) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/randall/sugar.rb', line 112 def from(type) unless @type == Hash then raise ArgumentError, 'Applied to generator for Hash only.' end case type when Class @options[:key_type] = type when Randall @options[:key] = type else @options[:key_type] = type.class end self end |
#greater_than(number) ⇒ Object Also known as: gt
57 58 59 60 61 62 63 64 |
# File 'lib/randall/sugar.rb', line 57 def greater_than(number) unless @type == Float or @type == Integer then raise ArgumentError, 'Applied to generator for number only.' end @options[:greater_than] = number self end |
#in_range(rg) ⇒ Object Also known as: between
76 77 78 79 80 81 82 83 |
# File 'lib/randall/sugar.rb', line 76 def in_range(rg) unless @type == Float or @type == Integer then raise ArgumentError, 'Applied to generator for number only.' end @options[:range] = rg self end |
#less_than(number) ⇒ Object Also known as: lt
47 48 49 50 51 52 53 54 |
# File 'lib/randall/sugar.rb', line 47 def less_than(number) unless @type == Float or @type == Integer then raise ArgumentError, 'Applied to generator for String only.' end @options[:less_than] = number self end |
#match(re) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/randall/sugar.rb', line 39 def match(re) unless @type == String then raise ArgumentError, 'Applied to generator for String only.' end self.restrict :like => re end |
#of(type) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/randall/sugar.rb', line 86 def of(type) unless @type == Array then raise ArgumentError, 'Applied to generator for Array only.' end case type when Randall @options[:item] = type when Class @options[:type] = type else @options[:type] = type.class end self end |
#that ⇒ Object Also known as: with, and
33 34 35 |
# File 'lib/randall/sugar.rb', line 33 def that self end |
#to(type) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/randall/sugar.rb', line 128 def to(type) unless @type == Hash then raise ArgumentError, 'Applied to generator for Hash only.' end case type when Class @options[:value_type] = type when Randall @options[:value] = type else @options[:value_type] = type.class end self end |
#with_arguments(*args) ⇒ Object
145 146 147 |
# File 'lib/randall/sugar.rb', line 145 def with_arguments(*args) self.restrict :args => args end |
#with_size(number) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/randall/sugar.rb', line 103 def with_size(number) unless @type == Hash or @type == Array then raise ArgumentError, 'Applied to generator for Hash and Array only.' end @options[:size] = number self end |