class MakeData::SampleGenerator
Attributes
shape[RW]
Public Class Methods
generate(category_name, method_name)
click to toggle source
# File lib/make_data.rb, line 39 def self.generate(category_name, method_name) Faker.const_get(category_name).send(method_name.to_sym) end
new(shape, ids)
click to toggle source
shape is a mapping from names to [category, method] pairs so, { name => ['FunnyName', 'name'], location => ['GameOfThrones', 'location'] }
# File lib/make_data.rb, line 34 def initialize(shape, ids) @shape = shape @ids = ids end
Public Instance Methods
generate(count)
click to toggle source
# File lib/make_data.rb, line 49 def generate(count) count.times.map do |id| make_one_from_shape.tap do |sample| # start ids at 1 sample[:id] = id + 1 if @ids end end end
make_one_from_shape()
click to toggle source
# File lib/make_data.rb, line 43 def make_one_from_shape @shape.map do |category, (faker_class, method)| [category, self.class.generate(faker_class, method)] end.to_h end