Class: MakeData::SampleGenerator
- Inherits:
-
Object
- Object
- MakeData::SampleGenerator
- Defined in:
- lib/make_data.rb
Instance Attribute Summary collapse
-
#shape ⇒ Object
Returns the value of attribute shape.
Class Method Summary collapse
Instance Method Summary collapse
- #generate(count) ⇒ Object
-
#initialize(shape, ids) ⇒ SampleGenerator
constructor
shape is a mapping from names to [category, method] pairs so, { name => [‘FunnyName’, ‘name’], location => [‘GameOfThrones’, ‘location’] }.
- #make_one_from_shape ⇒ Object
Constructor Details
#initialize(shape, ids) ⇒ SampleGenerator
shape is a mapping from names to [category, method] pairs so, { name => [‘FunnyName’, ‘name’], location => [‘GameOfThrones’, ‘location’] }
34 35 36 37 |
# File 'lib/make_data.rb', line 34 def initialize(shape, ids) @shape = shape @ids = ids end |
Instance Attribute Details
#shape ⇒ Object
Returns the value of attribute shape.
30 31 32 |
# File 'lib/make_data.rb', line 30 def shape @shape end |
Class Method Details
.generate(category_name, method_name) ⇒ Object
39 40 41 |
# 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 |
Instance Method Details
#generate(count) ⇒ Object
49 50 51 52 53 54 55 56 |
# 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 ⇒ Object
43 44 45 46 47 |
# 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 |