Class: AutoSeeding::Source

Inherits:
Object
  • Object
show all
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

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, options = {} )
  @column = column
  @type = type
  @rules = rules ? rules : {}
  @options = 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_booleanObject



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

#genObject



31
32
33
34
# File 'lib/auto-seeding/source.rb', line 31

def gen
  @retry = 100
  process @type
end