smart_csv 0.0.7 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ coverage/*
4
5
  pkg/*
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
data/Gemfile CHANGED
@@ -2,4 +2,9 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in smart_csv.gemspec
4
4
  gemspec
5
- gem 'rspec'
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'coveralls', require: false
10
+ end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Michał Szyma
1
+ Copyright (c) 2012-2013 Michał Szyma
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,59 +1,100 @@
1
1
  # SmartCSV
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/smart_csv.png)](http://badge.fury.io/rb/smart_csv)
4
+ [![Build Status](https://travis-ci.org/raglub/smart_csv.png)](https://travis-ci.org/raglub/smart_csv)
5
+ [![Code Climate](https://codeclimate.com/github/raglub/smart_csv.png)](https://codeclimate.com/github/raglub/smart_csv)
6
+ [![Dependency Status](https://gemnasium.com/raglub/smart_csv.png)](https://gemnasium.com/raglub/smart_csv)
7
+ [![Coverage Status](https://coveralls.io/repos/raglub/smart_csv/badge.png)](https://coveralls.io/r/raglub/smart_csv)
4
8
 
5
- Extend CSV class.
6
- This gem need header.
9
+ Extend CSV class. CSV can delete or select some records.
7
10
 
8
- ## FOR EXAMPLE
11
+ Compatible with:
12
+ Ruby 1.9.2, 1.9.3, and 2.0.0
13
+
14
+ # Getting started
15
+
16
+ For Example we can use following data
9
17
 
10
18
  ```ruby
11
19
  data = "id,firstname,lastname\n1,One,One\n2,Two,Two\n4,One,Four\n5,One,Five"
12
- @data = CSV.parse(data, {:col_sep => ',', :headers => true}
20
+ csv = CSV.parse(data, {:col_sep => ',', :headers => true}
13
21
  ```
14
- ## METHODS
15
22
 
16
- * Create a new record
23
+ And now we can:
24
+
25
+ * create a new record
26
+
17
27
  ```ruby
18
- @data.create("id"=> '13', "lastname" => '1992')
28
+ csv.create("id"=> '13', "lastname" => '1992')
19
29
  ```
20
- * Select records
30
+
31
+ * select records
32
+
21
33
  ```ruby
22
- @data.where('firstname' => 'One').where_not('id' => '4')
34
+ csv.where('firstname' => 'One').where_not('id' => '4')
23
35
  ```
24
- * Update record
36
+ * select opposite records
37
+
25
38
  ```ruby
26
- @data.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
39
+ csv.not{where('firstname' => 'One')}
27
40
  ```
28
- * Delete all records
41
+
42
+ * update record
43
+
29
44
  ```ruby
30
- @data.delete_all
45
+ csv.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
31
46
  ```
32
- * Delete all records from scope of condition
47
+
48
+ * delete all records
49
+
50
+ ```ruby
51
+ csv.delete_all
52
+ ```
53
+
54
+ * delete all records from scope of condition
55
+
33
56
  ```ruby
34
- @data.where('firstname' => 'One').delete_all
57
+ csv.where('firstname' => 'One').delete_all
35
58
  ```
36
- * Select all records which have 'id' attribute greater than 2
59
+
60
+ * select all records which have 'id' attribute greater than 2
61
+
37
62
  ```ruby
38
- @data.gt('id', '2')
63
+ csv.gt('id', '2')
39
64
  ```
40
- * Select all records which have 'id' attribute greater or equal 2
65
+
66
+ * select all records which have 'id' attribute greater or equal 2
67
+
41
68
  ```ruby
42
- @data.ge('id', '2')
69
+ csv.ge('id', '2')
43
70
  ```
44
- * Select all records which have 'id' attribute less than 2
71
+
72
+ * select all records which have 'id' attribute less than 2
73
+
45
74
  ```ruby
46
- @data.lt('id', '2')
75
+ csv.lt('id', '2')
47
76
  ```
48
- * Select all records which have 'id' attribute less or equal 2
77
+
78
+ * select all records which have 'id' attribute less or equal 2
79
+
49
80
  ```ruby
50
- @data.le('id', '2')
81
+ csv.le('id', '2')
51
82
  ```
52
- * Select all records which have 'firstname' attribute equal 'Tom'
83
+
84
+ * select all records which have 'firstname' attribute equal 'Tom'
85
+
53
86
  ```ruby
54
- @data.eq('firstname', 'Tom')
87
+ csv.eq('firstname', 'Tom')
55
88
  ```
56
- * Select all records which have 'firstname' attribute not equal 'Tom'
89
+
90
+ * select all records which have 'firstname' attribute not equal 'Tom'
91
+
57
92
  ```ruby
58
- @data.ne('firstname', 'Tom')
93
+ csv.ne('firstname', 'Tom')
59
94
  ```
95
+
96
+ # License
97
+
98
+ SmartCSV uses the MIT license. Please check the [LICENSE][] file for more details.
99
+
100
+ [license]: https://github.com/raglub/smart_csv/blob/master/LICENSE
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Run Spec'
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.verbose = false
7
+ end
8
+
9
+ task default: :spec
@@ -5,7 +5,8 @@ class CSV::Table
5
5
  attr_accessor :ancestor
6
6
 
7
7
  def where_not(*conditions)
8
- result = CSV::Table.new([])
8
+ result = prepare_new_table
9
+
9
10
  self.each do |record|
10
11
  counter = 0
11
12
  conditions.first.each {|key, value| counter += 1 unless record[key] == value.to_s}
@@ -14,9 +15,15 @@ class CSV::Table
14
15
  result
15
16
  end
16
17
 
18
+ # Select records which don't match with block
19
+ def not(&block)
20
+ result = prepare_new_table
21
+ result.table.replace(self.table - self.instance_eval(&block).table)
22
+ result
23
+ end
24
+
17
25
  def where(*conditions)
18
- result = CSV::Table.new([])
19
- result.ancestor = self.ancestor || self
26
+ result = prepare_new_table
20
27
 
21
28
  self.each do |record|
22
29
  counter = 0
@@ -1,3 +1,3 @@
1
1
  module SmartCSV
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -6,12 +6,13 @@ Gem::Specification.new do |gem|
6
6
  gem.name = 'smart_csv'
7
7
  gem.version = SmartCSV::VERSION
8
8
  gem.platform = Gem::Platform::RUBY
9
- gem.date = '2013-10-19'
9
+ gem.date = '2013-11-02'
10
10
  gem.authors = ['Michał Szyma']
11
11
  gem.email = ['raglub.ruby@gmail.com']
12
12
  gem.homepage = "https://github.com/raglub/smart_csv"
13
13
  gem.summary = %q{Extend CSV class.}
14
14
  gem.description = %q{Extend CSV class. CSV can delete or select some records.}
15
+ gem.license = "MIT"
15
16
 
16
17
  gem.files = `git ls-files`.split($\)
17
18
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -19,5 +20,9 @@ Gem::Specification.new do |gem|
19
20
 
20
21
  gem.require_paths = ['lib']
21
22
 
23
+ gem.add_dependency 'bundler', '>= 1.0.0'
24
+ gem.add_dependency 'rake'
25
+
22
26
  gem.add_development_dependency 'rspec', ">= 2.0.0"
27
+
23
28
  end
@@ -1,4 +1,4 @@
1
- require 'smart_csv'
1
+ require 'spec_helper'
2
2
 
3
3
  describe CSV::Row do
4
4
 
@@ -1,57 +1,66 @@
1
- require 'smart_csv'
1
+ require 'spec_helper'
2
2
 
3
3
  describe CSV::Table do
4
4
 
5
- let(:csv_data) {"id,firstname,lastname\n1,One,One\n2,Two,Two\n4,Four,Four\n5,Five,Five\n6,One,One"}
5
+ let(:csv_data) {"id,firstname,lastname
6
+ 1,One,One
7
+ 2,Two,Two
8
+ 4,Four,Four
9
+ 5,Five,Five
10
+ 6,One,One"}
6
11
 
7
- let(:parse_data) { CSV.parse(csv_data, {:col_sep => ',', :headers => true}) }
12
+ let(:csv) { CSV.parse(csv_data, {:col_sep => ',', :headers => true}) }
8
13
 
9
14
  it "should correct create one record" do
10
- parse_data.size.should eq(5)
11
- parse_data.create("id"=> '13', "lastname" => '1992')
12
- parse_data.size.should eq(6)
13
- parse_data[-1]["id"].should eql('13')
15
+ csv.size.should eq(5)
16
+ csv.create("id"=> '13', "lastname" => '1992')
17
+ csv.size.should eq(6)
18
+ csv[-1]["id"].should eql('13')
14
19
  end
15
20
 
16
21
  it "should correct select records" do
17
- parse_data.where('firstname' => 'One').size.should eql(2)
18
- parse_data.where('firstname' => 'One').where_not('id' => '6').size.should eql(1)
22
+ csv.where('firstname' => 'One').size.should eql(2)
23
+ csv.where('firstname' => 'One').where_not('id' => '6').size.should eql(1)
24
+ end
25
+
26
+ it "#not" do
27
+ csv.not{where('firstname' => "One")}.size.should eql(3)
19
28
  end
20
29
 
21
30
  it "should select records with id greater than 2" do
22
- parse_data.gt('id', 2).size.should eq(3)
31
+ csv.gt('id', 2).size.should eq(3)
23
32
  end
24
33
 
25
34
  it "should select records with id greater than or equal to 2" do
26
- parse_data.ge('id', 2).size.should eq(4)
35
+ csv.ge('id', 2).size.should eq(4)
27
36
  end
28
37
 
29
38
  it "should select records with id less than 2" do
30
- parse_data.lt('id', 2).size.should eq(1)
39
+ csv.lt('id', 2).size.should eq(1)
31
40
  end
32
41
 
33
42
  it "should select records with id less than or equal to 2" do
34
- parse_data.le('id', 2).size.should eq(2)
43
+ csv.le('id', 2).size.should eq(2)
35
44
  end
36
45
 
37
46
  it "should select records with firstname equal to 'Four'" do
38
- parse_data.eq('firstname', 'Four').size.should eq(1)
47
+ csv.eq('firstname', 'Four').size.should eq(1)
39
48
  end
40
49
 
41
50
  it "should select records with firstname not equal to 'Four'" do
42
- parse_data.ne('firstname', 'Four').size.should eq(4)
51
+ csv.ne('firstname', 'Four').size.should eq(4)
43
52
  end
44
53
 
45
54
  it "should correct delete records" do
46
- parse_data.size.should eql(5)
47
- parse_data.delete_all
48
- parse_data.size.should eql(0)
55
+ csv.size.should eql(5)
56
+ csv.delete_all
57
+ csv.size.should eql(0)
49
58
  end
50
59
 
51
60
  it "should correct delete records with selected group" do
52
- parse_data.size.should eql(5)
53
- parse_data.where('firstname' => 'One').delete_all
54
- parse_data.size.should eql(3)
61
+ csv.size.should eql(5)
62
+ csv.where('firstname' => 'One').delete_all
63
+ csv.size.should eql(3)
55
64
  end
56
65
 
57
66
  end
@@ -3,6 +3,9 @@ require 'bundler/setup'
3
3
 
4
4
  require 'smart_csv'
5
5
 
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
6
9
  RSpec.configure do |config|
7
10
  # some (optional) config here
8
11
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-19 00:00:00.000000000 Z
12
+ date: 2013-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
14
46
  - !ruby/object:Gem::Dependency
15
47
  name: rspec
16
48
  requirement: !ruby/object:Gem::Requirement
@@ -36,8 +68,9 @@ extra_rdoc_files: []
36
68
  files:
37
69
  - .gitignore
38
70
  - .rspec
71
+ - .travis.yml
39
72
  - Gemfile
40
- - LICENSE.txt
73
+ - LICENSE
41
74
  - README.md
42
75
  - Rakefile
43
76
  - lib/csv/csv.rb
@@ -50,7 +83,8 @@ files:
50
83
  - spec/csv/table/table_spec.rb
51
84
  - spec/spec_helper.rb
52
85
  homepage: https://github.com/raglub/smart_csv
53
- licenses: []
86
+ licenses:
87
+ - MIT
54
88
  post_install_message:
55
89
  rdoc_options: []
56
90
  require_paths: