faked_csv 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/faked_csv/cli.rb +5 -15
- data/lib/faked_csv/generator.rb +15 -0
- data/lib/faked_csv/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 295e76066eb9887b8ae9ba6a2fbbed0042287d53
|
4
|
+
data.tar.gz: d3863216a2f3e2f77686af20825c0b9e06b7e9cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ccd3b59f5d9f73f3395a8874df422119b345b41137f25f2348535113b31e34aa63ce0d5fefbb2e3162c08771f992e2882cbfaf2fdf7a2814a4d9aa396989f57
|
7
|
+
data.tar.gz: 68e211be1264ede26adc65d149a011aee3fb11862c881d1909d1661b98fbc42a13c8ad7b2ecb1750d64b32932f1e6d89eeaf74f99d016019da99085ba4cf9cad
|
data/lib/faked_csv/cli.rb
CHANGED
@@ -13,7 +13,7 @@ module FakedCSV
|
|
13
13
|
opts.on("-i", "--input JSON", "input path to json configuration file. default: ./faked.csv.json") do |input|
|
14
14
|
options[:input] = input
|
15
15
|
end
|
16
|
-
opts.on("-o", "--output CSV", "output path to csv file. if omit, print to
|
16
|
+
opts.on("-o", "--output CSV", "output path to csv file. if omit, print to output.csv") do |output|
|
17
17
|
options[:output] = output
|
18
18
|
end
|
19
19
|
opts.on("-v", "--version", "print version message") do
|
@@ -44,21 +44,11 @@ module FakedCSV
|
|
44
44
|
|
45
45
|
generator = FakedCSV::Generator.new FakedCSV::Config.new JSON.parse json
|
46
46
|
generator.generate
|
47
|
-
printer = FakedCSV::Printer.new(generator.headers, generator.rows)
|
48
|
-
s = printer.print
|
49
47
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
begin
|
56
|
-
File.open options[:output], 'w' do |f|
|
57
|
-
f.write s
|
58
|
-
end
|
59
|
-
rescue Exception=>e
|
60
|
-
puts "error writing to csv file: #{e.to_s}"
|
61
|
-
exit 2
|
48
|
+
out_file_name = options.has_key?(:output) ? options[:output] : 'output.csv'
|
49
|
+
puts "printing to file: #{out_file_name} ..."
|
50
|
+
File.open(out_file_name, 'w') do |file|
|
51
|
+
generator.print_to file
|
62
52
|
end
|
63
53
|
end
|
64
54
|
end
|
data/lib/faked_csv/generator.rb
CHANGED
@@ -11,6 +11,7 @@ module FakedCSV
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def rows
|
14
|
+
puts "transforming data to rows ..."
|
14
15
|
return @rows unless @rows.nil?
|
15
16
|
@rows = []
|
16
17
|
(0...@config.row_count).each do |r|
|
@@ -23,6 +24,16 @@ module FakedCSV
|
|
23
24
|
@rows
|
24
25
|
end
|
25
26
|
|
27
|
+
def print_to(writer)
|
28
|
+
(0...@config.row_count).each do |r|
|
29
|
+
@config.fields.each_with_index do |field, index|
|
30
|
+
suffix = (index == (@config.fields.size - 1)) ? '' : ','
|
31
|
+
writer.write("#{field[:data][r]}#{suffix}")
|
32
|
+
end
|
33
|
+
writer.write("\n")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
26
37
|
def generate
|
27
38
|
puts "preparing values ..."
|
28
39
|
prepare_values
|
@@ -42,9 +53,13 @@ module FakedCSV
|
|
42
53
|
elsif field[:rotate].nil? || field[:type] == :fixed
|
43
54
|
# not rotating? or fixed values? generate random value each time
|
44
55
|
puts "calling generator ..."
|
56
|
+
index = 0
|
45
57
|
@config.row_count.times do
|
46
58
|
field[:data] << _random_value(field)
|
59
|
+
print '.' if index % 10000 == 0
|
60
|
+
index += 1
|
47
61
|
end
|
62
|
+
puts
|
48
63
|
|
49
64
|
# inject user values if given and not fixed type
|
50
65
|
puts "injecting values ..."
|
data/lib/faked_csv/version.rb
CHANGED