class ZanTools::Seed
Constants
- TEXTS
Public Class Methods
generate(fields)
click to toggle source
# File lib/zan_tools/seed.rb, line 9 def self.generate(fields) Hash[fields.map do |name, conf| sample = case conf['type'].upper_camel when 'Long' then rand(0..1000) when 'String' then guess_string(name) when 'Date' then DateTime.now.to_s when 'Integer' then guess_integer(name) when 'Double' then (10000*rand()).to_i/100.0 else conf['type'] end [name, sample] end] end
generate_json(fields)
click to toggle source
# File lib/zan_tools/seed.rb, line 44 def self.generate_json(fields) JSON.generate(generate(fields)) end
guess_integer(name)
click to toggle source
# File lib/zan_tools/seed.rb, line 35 def self.guess_integer(name) case name.to_s when /^(is|has)[_A-Z]/ rand(0..1) else rand(0..10) end end
guess_string(name)
click to toggle source
# File lib/zan_tools/seed.rb, line 24 def self.guess_string(name) case name.to_s.downcase when /name|title|content|body|desc|comment/ TEXTS[rand(0 ... TEXTS.size/2) .. rand(TEXTS.size/2 ... TEXTS.size)] when /url/i "http://www.qima-inc.com/" else (0.. rand(5..10)).map { (97 + rand(26)).chr }.join end end