class QuickDataGenerator
Attributes
to_a[R]
Public Class Methods
new(s, rows: 3)
click to toggle source
# File lib/quickdata_generator.rb, line 11 def initialize(s, rows: 3) entries = SimpleConfig.new(s).to_h @to_a = rows.times.map { generate_value(entries) } end
Private Instance Methods
generate_value(entries)
click to toggle source
# File lib/quickdata_generator.rb, line 21 def generate_value(entries) entries.inject({}) do |r, x| key, s = x val = if /^(?<x1>\d+)\.\.(?<x2>\d+)$/ =~ s then Range.new(x1.to_i,x2.to_i).to_a.sample elsif /^(?<x1>\d+)\.(?<i>\d+)\.\.(?<x2>\d+(?:\.\d+)?)$/ =~ s then range = Range.new(x1.to_i,x2.to_i) a = [] increment = 1 / 10.0 ** i.length sum = "#{x1}.#{i}".to_f (sum += increment; a << sum) until sum >= x2.to_i a.map{|x| x.round(i.length)}.to_a.sample else s.split(/\s*,\s*/).sample end r.merge(key => val) end end