faked_csv 0.1.1 → 0.1.2

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: 56102a797c421e299e8ba038c686b6c513015b96
4
- data.tar.gz: fba1e160834bd6f27d90896c258e9e30b2c588f8
3
+ metadata.gz: 11b8ffae00bf6ea254e0fbcf8792b70b5bde6a6b
4
+ data.tar.gz: 0fffb33a679f705e73cce112a6809dd516123db5
5
5
  SHA512:
6
- metadata.gz: 53d314f1d7eeffb899dfe8c17629aa8245c98e19e22e4455f02b1508d28953f1bd7ee35c8989dbe85740765172223ac8d955e97c40202f4787f54a04a271d0cf
7
- data.tar.gz: 4704171816ab7dbd1751b72099ea51b8dccf92c543de2c679ca0cc6fc80edf9c47e0797aed507e78c4473f10c3f539bdac01d00cac9c849be9cc3146c7a65f83
6
+ metadata.gz: 7c577a730468fbbb87513688325c86f253357bdc4f86e627bf7f146df44b6b8d3230737a42a42c0a760d55d5e0aaeeb1022fbf9c20e49a81afea7d6961c3c944
7
+ data.tar.gz: 5cb90c0a5c1520f93c93c0a43b9579fa4cca529a590839af0f767a5297f5ff80218f366eb07b3ec83e6d17862c3517da493bb08b1097f6f6e62e34191ced8b52
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Build Status](https://travis-ci.org/jiananlu/faked_csv.svg?branch=master)](https://travis-ci.org/jiananlu/faked_csv)
1
2
  # Faking CSV data made easy
2
3
 
3
4
  faked_csv, using the awesome [Faker](https://github.com/stympy/faker) gem, helps you to generate CSV file with fake random data in your specified way. You may find it particularly useful in testing something out.
@@ -190,6 +191,25 @@ This indicates you want to use one of the methods from Faker gem. You can find t
190
191
 
191
192
  This indicates you only want to use the provided values in the output. Use `values` as a list to provide the values you want to use. They will be randomly picked independently each time; so no guarantee that every value in the list will be used. If you use `fixed` type, `inject` and `rotate` will be ignored.
192
193
 
194
+ #### inc:int
195
+
196
+ This indicates you want to generate inremental integers as the values for this column. Optional parameters are `start` to indicate the start count; `step` to indicate the step of each incrementation.
197
+
198
+ Example:
199
+
200
+ ```
201
+ ...
202
+ {
203
+ "name": "ID",
204
+ "type": "inc:int",
205
+ "start": 3,
206
+ "step": 2
207
+ }
208
+ ...
209
+ ```
210
+
211
+ will generate something like: [3, 5, 7, 9, 11, ...]
212
+
193
213
  ## Contributing
194
214
 
195
215
  1. Fork it ( https://github.com/jiananlu/faked_csv/fork )
data/Rakefile CHANGED
@@ -1,2 +1,16 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'cucumber'
3
+ require 'cucumber/rake/task'
4
+ require 'rspec/core/rake_task'
2
5
 
6
+ task :default => [:spec, :cucumber]
7
+
8
+ Cucumber::Rake::Task.new() do |t|
9
+ t.cucumber_opts = "features --format pretty"
10
+ end
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+
14
+ task :clean do
15
+ sh "rm -rf tmp"
16
+ end
@@ -50,6 +50,10 @@ module FakedCSV
50
50
  end
51
51
 
52
52
  case field[:type]
53
+ when /inc:int/i
54
+ field[:type] = :inc_int
55
+ field[:start] = cfg["start"].nil? ? 1 : cfg["start"].to_i
56
+ field[:step] = cfg["step"].nil? ? 1 : cfg["step"].to_i
53
57
  when /rand:int/i
54
58
  field[:type] = :rand_int
55
59
  if cfg["range"].nil?
@@ -30,7 +30,13 @@ module FakedCSV
30
30
  field[:data] = []
31
31
 
32
32
  # let's get some data!
33
- if field[:rotate].nil? || field[:type] == :fixed
33
+ if field[:type] == :inc_int
34
+ i = field[:start]
35
+ @config.row_count.times do
36
+ field[:data] << i
37
+ i += field[:step]
38
+ end
39
+ elsif field[:rotate].nil? || field[:type] == :fixed
34
40
  # not rotating? or fixed values? generate random value each time
35
41
  @config.row_count.times do
36
42
  field[:data] << _random_value(field)
@@ -53,7 +59,7 @@ module FakedCSV
53
59
  @config.fields.each do |field|
54
60
  # if it's fixed values or no rotate
55
61
  # we don't want to prepare values for this field
56
- if field[:type] == :fixed || field[:rotate].nil?
62
+ if [:inc_int, :fixed].include?(field[:type]) || field[:rotate].nil?
57
63
  next
58
64
  end
59
65
 
@@ -1,3 +1,3 @@
1
1
  module FakedCSV
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ {
2
+ "rows": 5,
3
+ "fields": [
4
+ {
5
+ "name": "ID",
6
+ "type": "inc:int",
7
+ "start": 3,
8
+ "step": 2
9
+ },
10
+ {
11
+ "name": "ID2",
12
+ "type": "inc:int"
13
+ }
14
+ ]
15
+ }
@@ -137,4 +137,11 @@ describe FakedCSV::Generator do
137
137
  generator.config.fields[0][:data].include?("aa").should == true
138
138
  generator.config.fields[0][:data].include?("bb").should == true
139
139
  end
140
+
141
+ it "increments integers" do
142
+ generator = FakedCSV::Generator.new FakedCSV::Config.new JSON.parse File.read 'spec/data/increment.csv.json'
143
+ generator.generate
144
+ generator.config.fields[0][:data].should == [3, 5, 7, 9, 11]
145
+ generator.config.fields[1][:data].should == [1, 2, 3, 4, 5]
146
+ end
140
147
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faked_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jianan Lu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-31 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -145,6 +145,7 @@ extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
147
  - ".gitignore"
148
+ - ".travis.yml"
148
149
  - Gemfile
149
150
  - LICENSE.txt
150
151
  - README.md
@@ -163,6 +164,7 @@ files:
163
164
  - lib/faked_csv/version.rb
164
165
  - spec/config_spec.rb
165
166
  - spec/data/basic.csv.json
167
+ - spec/data/increment.csv.json
166
168
  - spec/data/inject.csv.json
167
169
  - spec/data/rotate.csv.json
168
170
  - spec/fakerer_spec.rb
@@ -198,6 +200,7 @@ test_files:
198
200
  - features/support/setup.rb
199
201
  - spec/config_spec.rb
200
202
  - spec/data/basic.csv.json
203
+ - spec/data/increment.csv.json
201
204
  - spec/data/inject.csv.json
202
205
  - spec/data/rotate.csv.json
203
206
  - spec/fakerer_spec.rb