Class: ActiveWarehouse::Builder::StringGenerator
- Inherits:
-
Object
- Object
- ActiveWarehouse::Builder::StringGenerator
- Defined in:
- lib/active_warehouse/builder/random_data_builder.rb
Overview
A basic String generator
Instance Method Summary collapse
-
#generate(column, options = {}) ⇒ Object
Generate a random string.
-
#initialize(options = {}) ⇒ StringGenerator
constructor
Initialize the StringGenerator.
Constructor Details
#initialize(options = {}) ⇒ StringGenerator
Initialize the StringGenerator.
Options:
-
:values
: List of possible values -
:chars
: List of chars to use to generate random values
192 193 194 |
# File 'lib/active_warehouse/builder/random_data_builder.rb', line 192 def initialize(={}) @options = end |
Instance Method Details
#generate(column, options = {}) ⇒ Object
Generate a random string
Options:
-
:values
: An array of values to use. If not specified then random char values will be used. -
:chars
: An array of characters to use to generate random values (default [a..zA..Z])
200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/active_warehouse/builder/random_data_builder.rb', line 200 def generate(column, ={}) [:values] ||= @options[:values] [:chars] ||= @options[:chars] if [:values] [:values][rand([:values].length)] else s = '' chars = ([:chars] || ('a'..'z').to_a + ('A'..'Z').to_a) 0.upto(column.limit - 1) do |n| s << chars[rand(chars.length)] end s end end |