Module: Imposter
- Defined in:
- lib/imposter/version.rb,
lib/imposter.rb,
lib/imposter/csz.rb,
lib/imposter/noun.rb,
lib/imposter/verb.rb,
lib/imposter/phone.rb,
lib/imposter/animal.rb,
lib/imposter/mineral.rb,
lib/imposter/imposter.rb,
lib/imposter/vegtable.rb
Overview
Defined Under Namespace
Modules: VERSION
Classes: Animal, CSZ, Mineral, Noun, Phone, Street, Vegtable, Verb
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.gencsv(filename, cnt, fields, values) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/imposter.rb', line 16
def self.gencsv(filename,cnt,fields,values)
puts " #{filename.sub(/.csv/,'')}..."
vl = values
l = Array.new
m = Array.new(cnt,0)
FasterCSV.open(filename,"w") do |csv|
csv << fields
begin
(1..cnt).each do |i|
vl.each do |v|
begin
l << eval(v)
rescue
puts "Error evaluating " + v.to_s + " in " + filename
end
end
m[i,0] = l
csv << l
l.clear
end
rescue
puts "Some format/data error in " + filename
end
end
return m
end
|
.genimposters ⇒ Object
65
66
67
68
69
70
71
72
73
|
# File 'lib/imposter.rb', line 65
def self.genimposters
puts "File: " + __FILE__
models_dir = Dir.glob("test/imposter/*.yml")
models_dir.each do |imposter_yaml|
getfixtures parseyaml(imposter_yaml)
end
end
|
.getfixtures ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/imposter.rb', line 43
def self.getfixtures
fixtures_dir = Dir.glob("test/fixtures/*.csv")
if not fixtures_dir.empty? then
fixtures_dir.each do |fixture_csv|
fn = Pathname.new(fixture_csv).basename.to_s.chomp(File.extname(fixture_csv))
eval("@" + fn + "= FasterCSV.open(fixture_csv,'r').to_a rescue nil")
end
end
end
|
.letterify(letter_string) ⇒ Object
85
86
87
|
# File 'lib/imposter.rb', line 85
def self.letterify(letter_string)
letter_string.gsub(/\?/) { ('a'..'z').to_a.rand }
end
|
.numerify(number_string) ⇒ Object
81
82
83
|
# File 'lib/imposter.rb', line 81
def self.numerify(number_string)
number_string.gsub(/#/) { rand(10).to_s }
end
|
.parseyaml(yamlfilename) ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/imposter.rb', line 54
def self.parseyaml(yamlfilename)
imp_yaml = YAML.load(File.read(yamlfilename))
mn = imp_yaml.first[0]
imp_values = imp_yaml[mn]["fields"].values
imp_fields = imp_yaml[mn]["fields"].keys
imp_qty = imp_yaml[mn]["quantity"]
rl = gencsv("test/fixtures/" + mn.pluralize + ".csv",imp_qty,imp_fields, imp_values)
eval("@" + mn.pluralize + "= rl")
end
|
.pattern(string) ⇒ Object
89
90
91
|
# File 'lib/imposter.rb', line 89
def self.pattern(string)
self.letterify(self.numerify(string))
end
|
Instance Method Details
#announce(message) ⇒ Object
75
76
77
78
79
|
# File 'lib/imposter.rb', line 75
def announce(message)
text = "#{@version} #{name}: #{message}"
length = [0, 75 - text.length].max
write "== %s %s" % [text, "=" * length]
end
|