faked_csv 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6984c16e45f90ac775396b9c980e46d94152cf4e
4
- data.tar.gz: 4c87d07bff7d33ac8d9a33bab7141175c4b57d46
3
+ metadata.gz: 295e76066eb9887b8ae9ba6a2fbbed0042287d53
4
+ data.tar.gz: d3863216a2f3e2f77686af20825c0b9e06b7e9cd
5
5
  SHA512:
6
- metadata.gz: d0d095113517050b0e1e0f4b83f25b40125a8f770c5d42141036182e068b5a10b47fd2507d87f77216ee69f0a7ceba5708ce9f3799620373961f095103a160bf
7
- data.tar.gz: 2761601e98483458b92d01f45b1ed0fb2a22e7cd463cdd904ed2a873ce9acbc1be3dd9242dfacbcda9b3505d2c233fc75f26fbde314531734831ce4782f2e01f
6
+ metadata.gz: 1ccd3b59f5d9f73f3395a8874df422119b345b41137f25f2348535113b31e34aa63ce0d5fefbb2e3162c08771f992e2882cbfaf2fdf7a2814a4d9aa396989f57
7
+ data.tar.gz: 68e211be1264ede26adc65d149a011aee3fb11862c881d1909d1661b98fbc42a13c8ad7b2ecb1750d64b32932f1e6d89eeaf74f99d016019da99085ba4cf9cad
@@ -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 STDOUT") do |output|
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
- unless options.has_key? :output
51
- puts s
52
- return
53
- end
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
@@ -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 ..."
@@ -1,3 +1,3 @@
1
1
  module FakedCSV
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faked_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jianan Lu