fake_csv 0.0.2 → 0.0.3
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 +4 -4
- data/.gitignore +3 -0
- data/.rspec +3 -0
- data/Gemfile +8 -0
- data/fake_csv.gemspec +1 -0
- data/lib/fake_csv/format.rb +5 -0
- data/lib/fake_csv/g_data.rb +65 -0
- data/lib/fake_csv/readfile.rb +22 -0
- data/lib/fake_csv/version.rb +1 -1
- data/lib/fake_csv/writefile.rb +30 -0
- data/lib/fake_csv.rb +17 -3
- data/spec/format_spec.rb +8 -0
- data/spec/spec_helper.rb +66 -0
- data/tmp_spec/format_spec.rb +7 -0
- data/tmp_spec/spec_helper.rb +8 -0
- metadata +28 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d51e769776dd26a3a4bde105334044ebd766d11
|
4
|
+
data.tar.gz: 8429e0bc0ae89d2660fbebe32d0c8996067e301b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 775165e9228dadaef3e6e8214b4352d49b8c002150f9ffb273a9911455d337fe2ce4674446d039fa20b11421c3f5bc882a6b9424c942cf328caed2b20207f3ab
|
7
|
+
data.tar.gz: e47db6806be31789cf83472ce897d90fdf803f11b9e78a78a84917e25a5e39a0eaeb3142baa38df382b61efd3baaa32cd51dd7f78943db34af57f9caf92acb01
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
data/fake_csv.gemspec
CHANGED
@@ -0,0 +1,65 @@
|
|
1
|
+
require "faker"
|
2
|
+
|
3
|
+
class GenerateData
|
4
|
+
attr_accessor :data
|
5
|
+
def initialize
|
6
|
+
@data = []
|
7
|
+
end
|
8
|
+
def generate(format)
|
9
|
+
global_id = 0
|
10
|
+
format.each do |seq, index|
|
11
|
+
count = index[:format].scan(/\(([^\)]+)\)/).last.first.to_i
|
12
|
+
(1..count).each do |id|
|
13
|
+
result = nil
|
14
|
+
form = index[:content].split(',')
|
15
|
+
form.each do |value|
|
16
|
+
case value
|
17
|
+
when 'id'
|
18
|
+
global_id += 1
|
19
|
+
result = append_result(result, global_id.to_s)
|
20
|
+
when 'name'
|
21
|
+
result = append_result(result, Faker::Name.first_name)
|
22
|
+
when 'email'
|
23
|
+
result = append_result(result, Faker::Internet.email)
|
24
|
+
else
|
25
|
+
split = value.split('')
|
26
|
+
if split.include?("$") or split.include?("#")
|
27
|
+
string = ""
|
28
|
+
split.each do |value|
|
29
|
+
if value == "#"
|
30
|
+
string += ('a'..'z').to_a.shuffle[0, 1].join
|
31
|
+
elsif value == "$"
|
32
|
+
string += (0..9).to_a.shuffle[0, 1].join
|
33
|
+
else
|
34
|
+
string += value
|
35
|
+
end
|
36
|
+
end
|
37
|
+
result = append_result(result, string)
|
38
|
+
elsif split.include?("~")
|
39
|
+
# number range
|
40
|
+
first = value.split("~")[0].to_i
|
41
|
+
second = value.split("~")[1].to_i
|
42
|
+
number = (first..second).to_a.shuffle[0,1].join
|
43
|
+
result = append_result(result, number.to_s)
|
44
|
+
elsif split.include?("[")
|
45
|
+
# with require string
|
46
|
+
value_ary = value.scan(/\[([^\)]+)\]/).last.first
|
47
|
+
range = value_ary.split(" ").shuffle[0, 1].join
|
48
|
+
result = append_result(result, range)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
@data.push(result)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
def append_result(result, string)
|
57
|
+
if result.nil?
|
58
|
+
result = string
|
59
|
+
else
|
60
|
+
result = result + "," + string
|
61
|
+
end
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
|
4
|
+
class Readfile
|
5
|
+
attr_accessor :header, :format, :time
|
6
|
+
def initialize
|
7
|
+
@format = Hash.new
|
8
|
+
end
|
9
|
+
def read(file)
|
10
|
+
index = 0
|
11
|
+
File.foreach(file) do |row|
|
12
|
+
sep = row.split(":")
|
13
|
+
|
14
|
+
if sep[0] == "header"
|
15
|
+
@header = sep[1].chomp
|
16
|
+
elsif sep[0] =~ /format/i
|
17
|
+
@format.store(index, :format=>sep[0], :content=>sep[1].chomp)
|
18
|
+
index += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/fake_csv/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require "csv"
|
2
|
+
|
3
|
+
class Writefile
|
4
|
+
attr_writer :header
|
5
|
+
def initialize(header)
|
6
|
+
@header = header
|
7
|
+
end
|
8
|
+
def file(data)
|
9
|
+
make_csv("test.csv", "../datalater")
|
10
|
+
data.each do |content|
|
11
|
+
content = content
|
12
|
+
write_content(content, "test.csv", "../datalater")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
def make_csv(file_name=@file_name, path = @path)
|
16
|
+
CSV.open(path+"/"+file_name, 'w')
|
17
|
+
append_header(@header, file_name, path)
|
18
|
+
end
|
19
|
+
|
20
|
+
def append_header(header, file_name, path = nil)
|
21
|
+
write_content(header, file_name, path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_content(data, file_name=@file_name, path = @path)
|
25
|
+
data = data + "\n"
|
26
|
+
open(path+"/"+file_name, 'a') do |row|
|
27
|
+
row << data
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/fake_csv.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
+
path = File.expand_path(File.dirname(__FILE__))
|
2
|
+
$:.unshift(path) unless $:.include?(path)
|
1
3
|
require "fake_csv/version"
|
4
|
+
require "fake_csv/format"
|
5
|
+
require "fake_csv/readfile"
|
6
|
+
require "fake_csv/writefile"
|
7
|
+
require "fake_csv/g_data"
|
2
8
|
|
3
|
-
|
4
|
-
|
5
|
-
|
9
|
+
|
10
|
+
|
11
|
+
file_name = ARGV[0]
|
12
|
+
|
13
|
+
readfile = Readfile.new
|
14
|
+
readfile.read(file_name)
|
15
|
+
writefile = Writefile.new(readfile.header)
|
16
|
+
g_data = GenerateData.new
|
17
|
+
|
18
|
+
g_data.generate(readfile.format)
|
19
|
+
writefile.file(g_data.data)
|
data/spec/format_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler.setup
|
3
|
+
|
4
|
+
require 'fake_csv'
|
5
|
+
RSpec.configure do |config|
|
6
|
+
# The settings below are suggested to provide a good initial experience
|
7
|
+
# with RSpec, but feel free to customize to your heart's content.
|
8
|
+
=begin
|
9
|
+
# These two settings work together to allow you to limit a spec run
|
10
|
+
# to individual examples or groups you care about by tagging them with
|
11
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
12
|
+
# get run.
|
13
|
+
config.filter_run :focus
|
14
|
+
config.run_all_when_everything_filtered = true
|
15
|
+
|
16
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
17
|
+
# file, and it's useful to allow more verbose output when running an
|
18
|
+
# individual spec file.
|
19
|
+
if config.files_to_run.one?
|
20
|
+
# Use the documentation formatter for detailed output,
|
21
|
+
# unless a formatter has already been configured
|
22
|
+
# (e.g. via a command-line flag).
|
23
|
+
config.default_formatter = 'doc'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Print the 10 slowest examples and example groups at the
|
27
|
+
# end of the spec run, to help surface which specs are running
|
28
|
+
# particularly slow.
|
29
|
+
config.profile_examples = 10
|
30
|
+
|
31
|
+
# Run specs in random order to surface order dependencies. If you find an
|
32
|
+
# order dependency and want to debug it, you can fix the order by providing
|
33
|
+
# the seed, which is printed after each run.
|
34
|
+
# --seed 1234
|
35
|
+
config.order = :random
|
36
|
+
|
37
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
38
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
39
|
+
# test failures related to randomization by passing the same `--seed` value
|
40
|
+
# as the one that triggered the failure.
|
41
|
+
Kernel.srand config.seed
|
42
|
+
|
43
|
+
# rspec-expectations config goes here. You can use an alternate
|
44
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
45
|
+
# assertions if you prefer.
|
46
|
+
config.expect_with :rspec do |expectations|
|
47
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
48
|
+
# For more details, see:
|
49
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
50
|
+
expectations.syntax = :expect
|
51
|
+
end
|
52
|
+
|
53
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
54
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
55
|
+
config.mock_with :rspec do |mocks|
|
56
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
57
|
+
# For more details, see:
|
58
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
59
|
+
mocks.syntax = :expect
|
60
|
+
|
61
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
62
|
+
# a real object. This is generally recommended.
|
63
|
+
mocks.verify_partial_doubles = true
|
64
|
+
end
|
65
|
+
=end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fake_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JackHou
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09
|
11
|
+
date: 2014-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: generate fake csv
|
42
56
|
email:
|
43
57
|
- vjack070707@gmail.com
|
@@ -46,13 +60,22 @@ extensions: []
|
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
48
62
|
- .gitignore
|
63
|
+
- .rspec
|
49
64
|
- Gemfile
|
50
65
|
- LICENSE.txt
|
51
66
|
- README.md
|
52
67
|
- Rakefile
|
53
68
|
- fake_csv.gemspec
|
54
69
|
- lib/fake_csv.rb
|
70
|
+
- lib/fake_csv/format.rb
|
71
|
+
- lib/fake_csv/g_data.rb
|
72
|
+
- lib/fake_csv/readfile.rb
|
55
73
|
- lib/fake_csv/version.rb
|
74
|
+
- lib/fake_csv/writefile.rb
|
75
|
+
- spec/format_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- tmp_spec/format_spec.rb
|
78
|
+
- tmp_spec/spec_helper.rb
|
56
79
|
homepage: ''
|
57
80
|
licenses:
|
58
81
|
- MIT
|
@@ -77,4 +100,6 @@ rubygems_version: 2.1.11
|
|
77
100
|
signing_key:
|
78
101
|
specification_version: 4
|
79
102
|
summary: quickly generate fake csv
|
80
|
-
test_files:
|
103
|
+
test_files:
|
104
|
+
- spec/format_spec.rb
|
105
|
+
- spec/spec_helper.rb
|