smart_csv 0.0.5 → 0.0.6

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.
data/README.md CHANGED
@@ -1,27 +1,35 @@
1
- == SmartCSV
1
+ # SmartCSV
2
2
 
3
3
  Extend CSV class.
4
4
  This gem need header.
5
5
 
6
- == FOR EXAMPLE
6
+ ## FOR EXAMPLE
7
7
 
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}
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
 
11
- == METHODS
11
+ ## METHODS
12
12
 
13
13
  * Create a new record
14
- @data.create("id"=> '13', "lastname" => '1992')
14
+
15
+ @data.create("id"=> '13', "lastname" => '1992')
15
16
 
16
17
  * Select records
17
- @data.where('firstname' => 'One').where_not('id' => '4')
18
+
19
+ @data.where('firstname' => 'One').where_not('id' => '4')
18
20
 
19
21
  * Update record
20
- @data.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
22
+
23
+ @data.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
21
24
 
22
25
  * Delete all records
23
- @data.delete_all
26
+
27
+ @data.delete_all
24
28
 
25
29
  * Delete all records from scope of condition
26
- @data.where({'firstname' => 'One'}).delete_all
27
30
 
31
+ @data.where('firstname' => 'One').delete_all
32
+
33
+ * Select all records which have 'id' attribute greater than 2
34
+
35
+ @data.gt('id', 2)
@@ -26,6 +26,18 @@ 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
33
+
34
+ self.each do |record|
35
+ result << record if record[attribute].to_i > starter
36
+ end
37
+
38
+ result
39
+ end
40
+
29
41
  def create(*conditions)
30
42
  headers = self.headers
31
43
  row = headers.inject({}){|result, value| result[value] = nil; result}
@@ -1,3 +1,3 @@
1
1
  module SmartCSV
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/smart_csv.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'smart_csv/version'
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'smart_csv'
7
7
  gem.version = SmartCSV::VERSION
8
- gem.date = '2013-09-20'
8
+ gem.date = '2013-09-22'
9
9
  gem.authors = ['Michał Szyma']
10
10
  gem.email = ['raglub.ruby@gmail.com']
11
11
  gem.homepage = "https://github.com/raglub/smart_csv"
@@ -1,5 +1,5 @@
1
1
  require 'smart_csv'
2
- require 'pry'
2
+
3
3
  describe "Check class 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"}
@@ -7,9 +7,9 @@ describe "Check class CSV::Table" do
7
7
  let(:parse_data) { CSV.parse(csv_data, {:col_sep => ',', :headers => true}) }
8
8
 
9
9
  it "should correct create one record" do
10
- parse_data.size.should eql(5)
10
+ parse_data.size.should eq(5)
11
11
  parse_data.create("id"=> '13', "lastname" => '1992')
12
- parse_data.size.should eql(6)
12
+ parse_data.size.should eq(6)
13
13
  parse_data[-1]["id"].should eql('13')
14
14
  end
15
15
 
@@ -18,10 +18,8 @@ describe "Check class CSV::Table" do
18
18
  parse_data.where('firstname' => 'One').where_not('id' => '6').size.should eql(1)
19
19
  end
20
20
 
21
- it "should correct delete records" do
22
- parse_data.size.should eql(5)
23
- parse_data.delete_all
24
- parse_data.size.should eql(0)
21
+ it "should select records with id greater than 2" do
22
+ parse_data.gt('id', 2).size.should eq(3)
25
23
  end
26
24
 
27
25
  it "should correct delete records" do
@@ -30,9 +28,10 @@ describe "Check class CSV::Table" do
30
28
  parse_data.size.should eql(0)
31
29
  end
32
30
 
33
- it "should correct delete records" do
31
+ it "should correct delete records with selected group" do
34
32
  parse_data.size.should eql(5)
35
33
  parse_data.where('firstname' => 'One').delete_all
36
34
  parse_data.size.should eql(3)
37
35
  end
36
+
38
37
  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.5
4
+ version: 0.0.6
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-20 00:00:00.000000000 Z
12
+ date: 2013-09-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec