smart_csv 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,2 @@
1
1
  --color
2
2
  --format documentation
3
- --configure autotest
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michał Szyma
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,35 +1,59 @@
1
1
  # SmartCSV
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/smart_csv.png)](http://badge.fury.io/rb/smart_csv)
4
+
3
5
  Extend CSV class.
4
6
  This gem need header.
5
7
 
6
8
  ## FOR EXAMPLE
7
9
 
8
- data = "id,firstname,lastname\n1,One,One\n2,Two,Two\n4,One,Four\n5,One,Five"
9
- @data = CSV.parse(data, {:col_sep => ',', :headers => true}
10
-
10
+ ```ruby
11
+ 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}
13
+ ```
11
14
  ## METHODS
12
15
 
13
16
  * Create a new record
14
-
15
- @data.create("id"=> '13', "lastname" => '1992')
16
-
17
+ ```ruby
18
+ @data.create("id"=> '13', "lastname" => '1992')
19
+ ```
17
20
  * Select records
18
-
19
- @data.where('firstname' => 'One').where_not('id' => '4')
20
-
21
+ ```ruby
22
+ @data.where('firstname' => 'One').where_not('id' => '4')
23
+ ```
21
24
  * Update record
22
-
23
- @data.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
24
-
25
+ ```ruby
26
+ @data.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
27
+ ```
25
28
  * Delete all records
26
-
27
- @data.delete_all
28
-
29
+ ```ruby
30
+ @data.delete_all
31
+ ```
29
32
  * Delete all records from scope of condition
30
-
31
- @data.where('firstname' => 'One').delete_all
32
-
33
+ ```ruby
34
+ @data.where('firstname' => 'One').delete_all
35
+ ```
33
36
  * Select all records which have 'id' attribute greater than 2
34
-
35
- @data.gt('id', 2)
37
+ ```ruby
38
+ @data.gt('id', '2')
39
+ ```
40
+ * Select all records which have 'id' attribute greater or equal 2
41
+ ```ruby
42
+ @data.ge('id', '2')
43
+ ```
44
+ * Select all records which have 'id' attribute less than 2
45
+ ```ruby
46
+ @data.lt('id', '2')
47
+ ```
48
+ * Select all records which have 'id' attribute less or equal 2
49
+ ```ruby
50
+ @data.le('id', '2')
51
+ ```
52
+ * Select all records which have 'firstname' attribute equal 'Tom'
53
+ ```ruby
54
+ @data.eq('firstname', 'Tom')
55
+ ```
56
+ * Select all records which have 'firstname' attribute not equal 'Tom'
57
+ ```ruby
58
+ @data.ne('firstname', 'Tom')
59
+ ```
@@ -26,16 +26,36 @@ class CSV::Table
26
26
  result
27
27
  end
28
28
 
29
- # select all records which have attribute greater than starter
30
- def gt(attribute, starter)
31
- result = CSV::Table.new([])
32
- result.ancestor = self.ancestor || self
29
+ [
30
+ [:lt, :<],
31
+ [:le, :<=],
32
+ [:gt, :>],
33
+ [:ge, :>=],
34
+ ].each do |name, operator|
35
+ define_method name do |attribute, value|
36
+ result = prepare_new_table
33
37
 
34
- self.each do |record|
35
- result << record if record[attribute].to_i > starter
38
+ self.each do |record|
39
+ result << record if record[attribute].to_f.send(operator, value)
40
+ end
41
+
42
+ result
36
43
  end
44
+ end
37
45
 
38
- result
46
+ [
47
+ [:eq, :==],
48
+ [:ne, '!=']
49
+ ].each do |name, operator|
50
+ define_method name do |attribute, value|
51
+ result = prepare_new_table
52
+
53
+ self.each do |record|
54
+ result << record if record[attribute].send(operator, value)
55
+ end
56
+
57
+ result
58
+ end
39
59
  end
40
60
 
41
61
  def create(*conditions)
@@ -66,4 +86,13 @@ class CSV::Table
66
86
  end
67
87
  end
68
88
  end
89
+
90
+ private
91
+
92
+ def prepare_new_table
93
+ result = CSV::Table.new([])
94
+ result.ancestor = self.ancestor || self
95
+ result
96
+ end
97
+
69
98
  end
@@ -1,3 +1,3 @@
1
1
  module SmartCSV
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/smart_csv.gemspec CHANGED
@@ -3,20 +3,21 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
  require 'smart_csv/version'
4
4
 
5
5
  Gem::Specification.new do |gem|
6
- gem.name = 'smart_csv'
7
- gem.version = SmartCSV::VERSION
8
- gem.date = '2013-09-22'
9
- gem.authors = ['Michał Szyma']
10
- gem.email = ['raglub.ruby@gmail.com']
11
- gem.homepage = "https://github.com/raglub/smart_csv"
12
- gem.summary = %q{Extend CSV class.}
13
- gem.description = %q{Extend CSV class. CSV can delete or select some records.}
6
+ gem.name = 'smart_csv'
7
+ gem.version = SmartCSV::VERSION
8
+ gem.platform = Gem::Platform::RUBY
9
+ gem.date = '2013-10-19'
10
+ gem.authors = ['Michał Szyma']
11
+ gem.email = ['raglub.ruby@gmail.com']
12
+ gem.homepage = "https://github.com/raglub/smart_csv"
13
+ gem.summary = %q{Extend CSV class.}
14
+ gem.description = %q{Extend CSV class. CSV can delete or select some records.}
14
15
 
15
- gem.files = `git ls-files`.split($\)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
19
 
19
- gem.require_paths = ['lib']
20
+ gem.require_paths = ['lib']
20
21
 
21
- gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'rspec', ">= 2.0.0"
22
23
  end
@@ -1,6 +1,6 @@
1
1
  require 'smart_csv'
2
2
 
3
- describe "Check class CSV::Row" do
3
+ describe CSV::Row do
4
4
 
5
5
  before(:each) do
6
6
  data = "id,firstname,lastname\n1,One,One\n2,Two,Two\n4,Four,Four\n5,Five,Five\n6,One,One"
@@ -1,6 +1,6 @@
1
1
  require 'smart_csv'
2
2
 
3
- describe "Check class CSV::Table" do
3
+ describe CSV::Table do
4
4
 
5
5
  let(:csv_data) {"id,firstname,lastname\n1,One,One\n2,Two,Two\n4,Four,Four\n5,Five,Five\n6,One,One"}
6
6
 
@@ -22,6 +22,26 @@ describe "Check class CSV::Table" do
22
22
  parse_data.gt('id', 2).size.should eq(3)
23
23
  end
24
24
 
25
+ it "should select records with id greater than or equal to 2" do
26
+ parse_data.ge('id', 2).size.should eq(4)
27
+ end
28
+
29
+ it "should select records with id less than 2" do
30
+ parse_data.lt('id', 2).size.should eq(1)
31
+ end
32
+
33
+ it "should select records with id less than or equal to 2" do
34
+ parse_data.le('id', 2).size.should eq(2)
35
+ end
36
+
37
+ it "should select records with firstname equal to 'Four'" do
38
+ parse_data.eq('firstname', 'Four').size.should eq(1)
39
+ end
40
+
41
+ it "should select records with firstname not equal to 'Four'" do
42
+ parse_data.ne('firstname', 'Four').size.should eq(4)
43
+ end
44
+
25
45
  it "should correct delete records" do
26
46
  parse_data.size.should eql(5)
27
47
  parse_data.delete_all
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.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-22 00:00:00.000000000 Z
12
+ date: 2013-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 2.0.0
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '0'
29
+ version: 2.0.0
30
30
  description: Extend CSV class. CSV can delete or select some records.
31
31
  email:
32
32
  - raglub.ruby@gmail.com
@@ -35,7 +35,9 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - .gitignore
38
+ - .rspec
38
39
  - Gemfile
40
+ - LICENSE.txt
39
41
  - README.md
40
42
  - Rakefile
41
43
  - lib/csv/csv.rb
@@ -44,7 +46,6 @@ files:
44
46
  - lib/smart_csv.rb
45
47
  - lib/smart_csv/version.rb
46
48
  - smart_csv.gemspec
47
- - spec/.rspec
48
49
  - spec/csv/row/row_spec.rb
49
50
  - spec/csv/table/table_spec.rb
50
51
  - spec/spec_helper.rb
@@ -68,12 +69,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  version: '0'
69
70
  requirements: []
70
71
  rubyforge_project:
71
- rubygems_version: 1.8.24
72
+ rubygems_version: 1.8.25
72
73
  signing_key:
73
74
  specification_version: 3
74
75
  summary: Extend CSV class.
75
76
  test_files:
76
- - spec/.rspec
77
77
  - spec/csv/row/row_spec.rb
78
78
  - spec/csv/table/table_spec.rb
79
79
  - spec/spec_helper.rb