module Faker::Cli
Constants
- VERSION
Public Class Methods
generate(options)
click to toggle source
# File lib/faker/cli.rb, line 79 def self.generate options JSON.generate generate_result options[:numentries], make_fields end
generate_result(num, fields)
click to toggle source
# File lib/faker/cli.rb, line 83 def self.generate_result num, fields result = num.times.map do |n| obj = {} fields.each do |field| faker_module = Faker.const_get field.type[0] fake = faker_module.send(field.type[1], *field.arguments) obj[field.name] = string? int? fake end obj end end
int?(arg)
click to toggle source
# File lib/faker/cli.rb, line 97 def self.int? arg begin arg = Integer arg rescue ArgumentError, TypeError end arg end
make_fields()
click to toggle source
# File lib/faker/cli.rb, line 63 def self.make_fields ARGV.map do |arg| p = arg.split ":" p << "Lorem.word" if p.length == 1 name = p[0] type = p[1].match(/^[^\(\)]+/).to_s.split "." argmatch = p[1].match(/\(([^\)]+)\)/) args = [] args = argmatch[1].split(/,\s+/) if argmatch Field.new(name, type, args) end end
run()
click to toggle source
# File lib/faker/cli.rb, line 51 def self.run options = OptParse.parse ARGV options[:numentries] = OptParse::DEFAULT_NUM unless options.has_key? :numentries if ARGV.length < 1 then puts OptParse::parser.help exit end puts generate options end
string?(arg)
click to toggle source
# File lib/faker/cli.rb, line 106 def self.string? arg arg = arg.join " " if arg.is_a? Array arg end