Class: AutoSeeding::Source
- Inherits:
-
Object
- Object
- AutoSeeding::Source
- Defined in:
- lib/auto-seeding/source.rb
Constant Summary collapse
- DAY_SECONDS =
( 60 * 60 * 24 )
- MIN_INT =
0- MAX_INT =
1_000_000- MIN_FLOAT =
0.0- MAX_FLOAT =
1000.0- MONTH_SECONDS =
( DAY_SECONDS * 30 ).freeze
- VOWELS =
%w(a e i o u).freeze
- CONSONANTS =
(('a'..'z').to_a - VOWELS).freeze
Class Method Summary collapse
Instance Method Summary collapse
- #gen ⇒ Object
-
#initialize(column, type, rules, options = {}) ⇒ Source
constructor
A new instance of Source.
Constructor Details
#initialize(column, type, rules, options = {}) ⇒ Source
Returns a new instance of Source.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/auto-seeding/source.rb', line 13 def initialize( column, type, rules, = {} ) @column = column @type = type @rules = rules ? rules : {} @options = || {} if @options[:source_model] && @options[:source_method] @source_class = Object.const_get @options[:source_model] @source_method = @options[:source_method].to_sym @source_args = @options[:source_args] else @source_class = AutoSeeding::Source @source_method = :random_string @source_args = nil end @uniqueness = {} self end |
Class Method Details
.random_boolean ⇒ Object
36 37 38 |
# File 'lib/auto-seeding/source.rb', line 36 def self.random_boolean [false, true].sample end |
.random_string(words = 10) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/auto-seeding/source.rb', line 40 def self.random_string( words = 10 ) (1..rand(words)+1).map do (0..rand(10)+1).map do |i| i % 2 == 0 ? CONSONANTS.sample : VOWELS.sample end.join end.join( ' ' ).capitalize end |
Instance Method Details
#gen ⇒ Object
31 32 33 34 |
# File 'lib/auto-seeding/source.rb', line 31 def gen @retry = 100 process @type end |