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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7bc0a06747db2a310bdf442c4f49d54cafaa913
4
- data.tar.gz: 08258a14a984cb4e2c5c77465728bb97c3ed7e97
3
+ metadata.gz: 0d51e769776dd26a3a4bde105334044ebd766d11
4
+ data.tar.gz: 8429e0bc0ae89d2660fbebe32d0c8996067e301b
5
5
  SHA512:
6
- metadata.gz: 318ae23975b5dc2961984037ee9465409c10798c7c8f68de1b5e0ae03b254cd53e0f70a1cd4eb34c3952549cc51811cba29172d1566ba0faf6b0be8b338886fe
7
- data.tar.gz: 99616aa285fe4c43f4c5a9109347b5b273e943515312198923538d65ca45fd1deff4f1b6a7bb18ff76cc2868183ce050e972110ac710160ac7caff043e607fb7
6
+ metadata.gz: 775165e9228dadaef3e6e8214b4352d49b8c002150f9ffb273a9911455d337fe2ce4674446d039fa20b11421c3f5bc882a6b9424c942cf328caed2b20207f3ab
7
+ data.tar.gz: e47db6806be31789cf83472ce897d90fdf803f11b9e78a78a84917e25a5e39a0eaeb3142baa38df382b61efd3baaa32cd51dd7f78943db34af57f9caf92acb01
data/.gitignore CHANGED
@@ -15,3 +15,6 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ datalater
19
+ test
20
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,11 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in fake_csv.gemspec
4
4
  gemspec
5
+
6
+ gem 'rspec'
7
+ gem 'faker'
8
+ group :development do
9
+ gem 'guard'
10
+ gem 'guard-rspec'
11
+ gem 'pry'
12
+ end
data/fake_csv.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
23
24
  end
@@ -0,0 +1,5 @@
1
+ require 'csv'
2
+
3
+ module Format
4
+
5
+ end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module FakeCsv
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
- module FakeCsv
4
- p "hi"
5
- end
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)
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe FakeCsv do
4
+ it "should be in any roles assigned to it" do
5
+ fake = FakeCsv.new
6
+ fake.should be_in_csv("sdf")
7
+ end
8
+ end
@@ -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
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe FakeCsv do
4
+ before do
5
+ @fake_csv = FakeCsv.new
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'your_gem_name' # and any other gems you need
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ 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.2
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-27 00:00:00.000000000 Z
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