Class: FakedCSV::Fakerer

Inherits:
Object
  • Object
show all
Defined in:
lib/faked_csv/fakerer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Fakerer

Returns a new instance of Fakerer.



9
10
11
12
13
14
15
16
17
# File 'lib/faked_csv/fakerer.rb', line 9

def initialize(type)
    @type = type
    faker, class_name, @method = @type.split ':'
    begin
        @class = Kernel.const_get("Faker::#{_camelize class_name}")
    rescue
        raise "unsupported faker class: #{class_name}"
    end
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/faked_csv/fakerer.rb', line 8

def type
  @type
end

Instance Method Details

#_camelize(str) ⇒ Object



27
28
29
# File 'lib/faked_csv/fakerer.rb', line 27

def _camelize(str)
    str.split('_').map {|w| w.capitalize}.join
end

#fakeObject



19
20
21
22
23
24
25
# File 'lib/faked_csv/fakerer.rb', line 19

def fake
    begin
        @class.send @method
    rescue
        raise "unsupported faker method: #{@method}"
    end
end