csv_importer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,3 +2,6 @@
2
2
 
3
3
  * 1 major enhancement:
4
4
  * Initial release
5
+
6
+ === 0.0.3 2010-11-20
7
+ * 1 major enhancement, got gem working properly...finally.
@@ -1 +1 @@
1
- For more information on csv_importer, see http://csv_importer.rubyforge.org
1
+ For more information on csv_importer, see http://github.com/sparkboxx/csv_importer
@@ -1,6 +1,6 @@
1
1
  == DESCRIPTION:
2
2
 
3
- http://github.com/sparkboxx/csv-importer
3
+ http://github.com/sparkboxx/csv_importer
4
4
 
5
5
  Ever needed to import csv files where every row needs to be converted into a model?
6
6
 
@@ -16,29 +16,29 @@ You can provide a dictionary with translations between the CSV column names and
16
16
  require 'csv_importer'
17
17
 
18
18
  class Product < Struct.new(:title, :price, :brand, :image); end
19
+
19
20
  file = File.open("filename.csv", "rb")
20
- importer = CSV_Importer::Importer.new(file, Product)
21
- products = importer.objects
21
+ importer = CSVImporter::Importer.new(file, Product) # Load file and Model
22
+ importer.objects # Import and return objects
22
23
 
23
- or
24
+ This will look at the first line of filename.csv, and get the column names. It will then try and initialize a Product for each line using the values of the given columns.
25
+ It does NOT save the objects yet. For use with ActiveRecord objects you can provide an argument to call save on every product when created
24
26
 
25
- require 'csv_importer'
27
+ products = importer.object(true)
28
+
29
+ The attributes of ActiveRecord objects are assigned using update_attributes for increased security. Beware, that if the model is not an ActiveRecord model mass assigning attributes by CSV column name might impose a security risk if you don't know the exact names of the CSV columns.
30
+
31
+
32
+ You can also use a dictionary to "translate" between the column names in the CSV and the attribute names of your model
26
33
 
27
34
  class Product < Struct.new(:title, :price, :brand, :image); end
28
35
  csv_string = "title, the price, the brand \n jeans, 10, fashionable"
36
+
29
37
  dictionary = {"the brand"=>"brand", "the price"=>"price"}
30
- importer = CSV_Importer::Importer.new(csv_string, Product, dictionary)
38
+
39
+ importer = CSVImporter::Importer.new(csv_string, Product, dictionary)
31
40
  products = importer.objects
32
41
 
33
- For use with ActiveRecord objects you can provide an argument to call save on every product when created
34
-
35
- products = importer.object(true)
36
-
37
- The attributes of ActiveRecord objects are assigned using update_attributes for increased security.
38
-
39
- Beware, that if the model is not an ActiveRecord model mass assigning attributes by CSV column name might impose a security risk if you don't know the exact names of the CSV columns.
40
-
41
- In a next release a stripped down version of active records "attr_accessible" will be bundled with the gem.
42
42
 
43
43
  == REQUIREMENTS:
44
44
 
@@ -52,7 +52,7 @@ In a next release a stripped down version of active records "attr_accessible" wi
52
52
 
53
53
  (The MIT License)
54
54
 
55
- Copyright (c) 2009 Sparkboxx
55
+ Copyright (c) 2010 Sparkboxx
56
56
 
57
57
  Permission is hereby granted, free of charge, to any person obtaining
58
58
  a copy of this software and associated documentation files (the
@@ -1,5 +1,5 @@
1
1
  module CSVImporter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  require 'csv'
4
4
 
5
5
 
@@ -1,14 +1,14 @@
1
- Description;Brand;SellPrice;SalePrice;Image;Category;ArticleCode
2
- SINGLE JERSEY L.S R;PME Jeans; 59.95; 59.95;http://www.softwear.nl/ism/bouchier/images/JTS91573.JPG;T-shirts;JTS91573
3
- MONTANA L.SL. GRAND;PME legend; 59.95; 59.95;http://www.softwear.nl/ism/bouchier/images/PTS88510.JPG;T-shirts;PTS88510
4
- CO DOUBLE JERSEY, 1;Cast Iron; 29.95; 29.95;http://www.softwear.nl/ism/bouchier/images/CAC91101.JPG;Belts/ Keyholders;CAC91101
5
- PLAYER L.SLV. VEST;Cast Iron; 99.95; 99.95;http://www.softwear.nl/ism/bouchier/images/CKW91406.JPG;Knitwear;CKW91406
6
- SLUBOR L.SL POLO;Cast Iron; 79.95; 79.95;http://www.softwear.nl/ism/bouchier/images/CPS91301.JPG;Polo l.sl;CPS91301
7
- BEAR CLAW FLOWER -;Cast Iron; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/CSI91601.JPG;Shirts;CSI91601
8
- KHENSU LSE - MULTI;Cast Iron; 129.95; 129.95;http://www.softwear.nl/ism/bouchier/images/CTR91202-960.JPG;Pants;CTR91202-960
9
- NYLON FLIGHT BOMBER;PME legend; 179.95; 179.95;http://www.softwear.nl/ism/bouchier/images/JA86112.JPG;Jackets;JA86112
10
- RATON LONG JACKET;Vanguard; 239.95; 239.95;http://www.softwear.nl/ism/bouchier/images/VJA86149.JPG;Jackets;VJA86149
11
- OXFORD PANT, COTTON;Vanguard; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/VTR86422-739.JPG;Pants;VTR86422-739
12
- MERIDIAN S.SL R-NEC;Vanguard; 49.95; 49.95;http://www.softwear.nl/ism/bouchier/images/VTSS86301.JPG;T-shirts;VTSS86301
13
- ;PME legend; 24.95; 24.95;http://www.softwear.nl/ism/bouchier/images/PAC91002.JPG;Belts/ Keyholders;PAC91002
14
- COTTON PLAITED V-NE;PME legend; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/PKW91339.JPG;Knitwear;PKW91339
1
+ Description;Brand;SellPrice;SalePrice;Image;Category;ArticleCode
2
+ SINGLE JERSEY L.S R;PME Jeans; 59.95; 59.95;http://www.softwear.nl/ism/bouchier/images/JTS91573.JPG;T-shirts;JTS91573
3
+ MONTANA L.SL. GRAND;PME legend; 59.95; 59.95;http://www.softwear.nl/ism/bouchier/images/PTS88510.JPG;T-shirts;PTS88510
4
+ CO DOUBLE JERSEY, 1;Cast Iron; 29.95; 29.95;http://www.softwear.nl/ism/bouchier/images/CAC91101.JPG;Belts/ Keyholders;CAC91101
5
+ PLAYER L.SLV. VEST;Cast Iron; 99.95; 99.95;http://www.softwear.nl/ism/bouchier/images/CKW91406.JPG;Knitwear;CKW91406
6
+ SLUBOR L.SL POLO;Cast Iron; 79.95; 79.95;http://www.softwear.nl/ism/bouchier/images/CPS91301.JPG;Polo l.sl;CPS91301
7
+ BEAR CLAW FLOWER -;Cast Iron; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/CSI91601.JPG;Shirts;CSI91601
8
+ KHENSU LSE - MULTI;Cast Iron; 129.95; 129.95;http://www.softwear.nl/ism/bouchier/images/CTR91202-960.JPG;Pants;CTR91202-960
9
+ NYLON FLIGHT BOMBER;PME legend; 179.95; 179.95;http://www.softwear.nl/ism/bouchier/images/JA86112.JPG;Jackets;JA86112
10
+ RATON LONG JACKET;Vanguard; 239.95; 239.95;http://www.softwear.nl/ism/bouchier/images/VJA86149.JPG;Jackets;VJA86149
11
+ OXFORD PANT, COTTON;Vanguard; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/VTR86422-739.JPG;Pants;VTR86422-739
12
+ MERIDIAN S.SL R-NEC;Vanguard; 49.95; 49.95;http://www.softwear.nl/ism/bouchier/images/VTSS86301.JPG;T-shirts;VTSS86301
13
+ ;PME legend; 24.95; 24.95;http://www.softwear.nl/ism/bouchier/images/PAC91002.JPG;Belts/ Keyholders;PAC91002
14
+ COTTON PLAITED V-NE;PME legend; 89.95; 89.95;http://www.softwear.nl/ism/bouchier/images/PKW91339.JPG;Knitwear;PKW91339
@@ -69,7 +69,7 @@ describe "Initialze CSV" do
69
69
  it "should create the collection of objects" do
70
70
  dictionary = {"Description"=>"title", "Saleprice"=>"Price"}
71
71
  importer = Importer.new(File.open(File.dirname(__FILE__)+ "/csv/sample.csv", "rb"), Product, dictionary)
72
- importer.objects.count.should == 5 #See spec/csv/sample.csv
72
+ importer.objects.count.should == 13 #See spec/csv/sample.csv
73
73
  end
74
74
 
75
75
  it "shoud not turn the title line into an object" do
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
5
11
  platform: ruby
6
12
  authors:
7
13
  - Sparkboxx
@@ -9,21 +15,43 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-11-05 00:00:00 +01:00
18
+ date: 2010-11-21 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
- name: hoe
22
+ name: rubyforge
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 2
32
+ - 0
33
+ - 4
34
+ version: 2.0.4
17
35
  type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: hoe
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
20
42
  requirements:
21
43
  - - ">="
22
44
  - !ruby/object:Gem::Version
23
- version: 2.3.3
24
- version:
45
+ hash: 21
46
+ segments:
47
+ - 2
48
+ - 6
49
+ - 1
50
+ version: 2.6.1
51
+ type: :development
52
+ version_requirements: *id002
25
53
  description: |-
26
- http://github.com/sparkboxx/csv-importer
54
+ http://github.com/sparkboxx/csv_importer
27
55
 
28
56
  Ever needed to import csv files where every row needs to be converted into a model?
29
57
 
@@ -57,7 +85,7 @@ files:
57
85
  - spec/spec_helper.rb
58
86
  - tasks/rspec.rake
59
87
  has_rdoc: true
60
- homepage: http://github.com/sparkboxx/csv-importer
88
+ homepage: http://github.com/sparkboxx/csv_importer
61
89
  licenses: []
62
90
 
63
91
  post_install_message:
@@ -67,23 +95,29 @@ rdoc_options:
67
95
  require_paths:
68
96
  - lib
69
97
  required_ruby_version: !ruby/object:Gem::Requirement
98
+ none: false
70
99
  requirements:
71
100
  - - ">="
72
101
  - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
73
105
  version: "0"
74
- version:
75
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
+ none: false
76
108
  requirements:
77
109
  - - ">="
78
110
  - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
79
114
  version: "0"
80
- version:
81
115
  requirements: []
82
116
 
83
117
  rubyforge_project: csv_importer
84
- rubygems_version: 1.3.5
118
+ rubygems_version: 1.3.7
85
119
  signing_key:
86
120
  specification_version: 3
87
- summary: http://github.com/sparkboxx/csv-importer Ever needed to import csv files where every row needs to be converted into a model? The CSV importer turns every row of a CSV file into an object
121
+ summary: http://github.com/sparkboxx/csv_importer Ever needed to import csv files where every row needs to be converted into a model? The CSV importer turns every row of a CSV file into an object
88
122
  test_files: []
89
123