Class: DummyLogGenerator::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/dummy_log_generator/generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



6
7
8
9
# File 'lib/dummy_log_generator/generator.rb', line 6

def initialize
  @fields = {}
  @rand = ::DummyLogGenerator::Random.new
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



3
4
5
# File 'lib/dummy_log_generator/generator.rb', line 3

def fields
  @fields
end

#randObject (readonly)

Returns the value of attribute rand.



4
5
6
# File 'lib/dummy_log_generator/generator.rb', line 4

def rand
  @rand
end

Instance Method Details

#generate(prev_data = {}) ⇒ Object Also known as: gen



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dummy_log_generator/generator.rb', line 11

def generate(prev_data = {})
  data = {}
  fields.each do |key, opts|
    opts = opts.dup
    type = opts.delete(:type)
    opts[:prev] = prev_data[key]
    data[key] = case type
                when :datetime
                  rand.datetime(opts)
                when :string
                  rand.string(opts)
                when :integer
                  rand.integer(opts)
                when :float
                  rand.float(opts)
                else
                  raise ConfigError.new(type)
                end
  end
  data
end