csv-mapper 0.0.4 → 0.5.0

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.
@@ -1 +1 @@
1
- --colour
1
+ --color
@@ -1,10 +1,9 @@
1
- begin
2
- require 'spec'
3
- rescue LoadError
4
- require 'rubygems'
5
- gem 'rspec'
6
- require 'spec'
7
- end
8
-
9
- $:.unshift(File.dirname(__FILE__) + '/../lib')
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
3
  require 'csv-mapper'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csv-mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Luke Pillow
@@ -9,107 +14,93 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-08-05 00:00:00 -05:00
17
+ date: 2010-05-12 00:00:00 -05:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
- name: fastercsv
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
23
- version: 1.4.0
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: newgem
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
27
32
  type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.2.3
34
- version:
33
+ version_requirements: *id001
35
34
  - !ruby/object:Gem::Dependency
36
- name: hoe
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
35
+ name: fastercsv
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
40
38
  requirements:
41
39
  - - ">="
42
40
  - !ruby/object:Gem::Version
43
- version: 1.8.0
44
- version:
45
- description: CsvMapper is a small library intended to simplify the common steps involved with importing CSV files to a usable form in Ruby. CsvMapper is compatible with recent 1.8 versions of Ruby as well as Ruby 1.9+
46
- email:
47
- - lpillow@gmail.com
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ description: CSV Mapper makes it easy to import data from CSV files directly to a collection of any type of Ruby object. The simplest way to create mappings is declare the names of the attributes in the order corresponding to the CSV file column order.
47
+ email: lpillow@gmail.com
48
48
  executables: []
49
49
 
50
50
  extensions: []
51
51
 
52
52
  extra_rdoc_files:
53
53
  - History.txt
54
- - Manifest.txt
55
- - PostInstall.txt
54
+ - LICENSE
56
55
  - README.rdoc
57
- - website/index.txt
58
56
  files:
57
+ - .gitignore
59
58
  - History.txt
60
- - Manifest.txt
61
- - PostInstall.txt
59
+ - LICENSE
62
60
  - README.rdoc
63
61
  - Rakefile
64
- - config/website.yml
62
+ - VERSION
65
63
  - lib/csv-mapper.rb
66
- - script/console
67
- - script/destroy
68
- - script/generate
69
- - script/txt2html
70
- - spec/csv-mapper_attribute_map_spec.rb
71
- - spec/csv-mapper_row_map_spec.rb
64
+ - lib/csv-mapper/attribute_map.rb
65
+ - lib/csv-mapper/row_map.rb
66
+ - spec/csv-mapper/csv-mapper_attribute_map_spec.rb
67
+ - spec/csv-mapper/csv-mapper_row_map_spec.rb
72
68
  - spec/csv-mapper_spec.rb
73
69
  - spec/spec.opts
74
70
  - spec/spec_helper.rb
75
71
  - spec/test.csv
76
- - tasks/rspec.rake
77
- - test/test_csv-mapper.rb
78
- - test/test_helper.rb
79
- - website/index.html
80
- - website/index.txt
81
- - website/javascripts/rounded_corners_lite.inc.js
82
- - website/stylesheets/screen.css
83
- - website/template.html.erb
84
72
  has_rdoc: true
85
- homepage:
73
+ homepage: http://github.com/pillowfactory/csv-mapper
86
74
  licenses: []
87
75
 
88
76
  post_install_message:
89
77
  rdoc_options:
90
- - --main
91
- - README.rdoc
78
+ - --charset=UTF-8
92
79
  require_paths:
93
80
  - lib
94
81
  required_ruby_version: !ruby/object:Gem::Requirement
95
82
  requirements:
96
83
  - - ">="
97
84
  - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
98
87
  version: "0"
99
- version:
100
88
  required_rubygems_version: !ruby/object:Gem::Requirement
101
89
  requirements:
102
90
  - - ">="
103
91
  - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
104
94
  version: "0"
105
- version:
106
95
  requirements: []
107
96
 
108
- rubyforge_project: csv-mapper
109
- rubygems_version: 1.3.4
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.6
110
99
  signing_key:
111
100
  specification_version: 3
112
- summary: CsvMapper is a small library intended to simplify the common steps involved with importing CSV files to a usable form in Ruby
101
+ summary: CsvMapper is a small library intended to simplify the common steps involved with importing CSV files to a usable form in Ruby.
113
102
  test_files:
114
- - test/test_csv-mapper.rb
115
- - test/test_helper.rb
103
+ - spec/csv-mapper/csv-mapper_attribute_map_spec.rb
104
+ - spec/csv-mapper/csv-mapper_row_map_spec.rb
105
+ - spec/csv-mapper_spec.rb
106
+ - spec/spec_helper.rb
@@ -1,25 +0,0 @@
1
- History.txt
2
- Manifest.txt
3
- PostInstall.txt
4
- README.rdoc
5
- Rakefile
6
- config/website.yml
7
- lib/csv-mapper.rb
8
- script/console
9
- script/destroy
10
- script/generate
11
- script/txt2html
12
- spec/csv-mapper_attribute_map_spec.rb
13
- spec/csv-mapper_row_map_spec.rb
14
- spec/csv-mapper_spec.rb
15
- spec/spec.opts
16
- spec/spec_helper.rb
17
- spec/test.csv
18
- tasks/rspec.rake
19
- test/test_csv-mapper.rb
20
- test/test_helper.rb
21
- website/index.html
22
- website/index.txt
23
- website/javascripts/rounded_corners_lite.inc.js
24
- website/stylesheets/screen.css
25
- website/template.html.erb
@@ -1,5 +0,0 @@
1
-
2
- For more information on CSV Mapper, see http://csv-mapper.rubyforge.org
3
-
4
-
5
-
@@ -1,2 +0,0 @@
1
- host: pillowfactory@rubyforge.org
2
- remote_dir: /var/www/gforge-projects/csv-mapper
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # File: script/console
3
- irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
-
5
- libs = " -r irb/completion"
6
- # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
- # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
- libs << " -r #{File.dirname(__FILE__) + '/../lib/csv-mapper.rb'}"
9
- puts "Loading csv-mapper gem"
10
- exec "#{irb} #{libs} --simple-prompt"
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
@@ -1,71 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- load File.dirname(__FILE__) + "/../Rakefile"
4
- require 'rubyforge'
5
- require 'redcloth'
6
- require 'syntax/convertors/html'
7
- require 'erb'
8
-
9
- download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
10
- version = $hoe.version
11
-
12
- def rubyforge_project_id
13
- RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
14
- end
15
-
16
- class Fixnum
17
- def ordinal
18
- # teens
19
- return 'th' if (10..19).include?(self % 100)
20
- # others
21
- case self % 10
22
- when 1: return 'st'
23
- when 2: return 'nd'
24
- when 3: return 'rd'
25
- else return 'th'
26
- end
27
- end
28
- end
29
-
30
- class Time
31
- def pretty
32
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
33
- end
34
- end
35
-
36
- def convert_syntax(syntax, source)
37
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
38
- end
39
-
40
- if ARGV.length >= 1
41
- src, template = ARGV
42
- template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
43
- else
44
- puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
45
- exit!
46
- end
47
-
48
- template = ERB.new(File.open(template).read)
49
-
50
- title = nil
51
- body = nil
52
- File.open(src) do |fsrc|
53
- title_text = fsrc.readline
54
- body_text_template = fsrc.read
55
- body_text = ERB.new(body_text_template).result(binding)
56
- syntax_items = []
57
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
58
- ident = syntax_items.length
59
- element, syntax, source = $1, $2, $3
60
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
61
- "syntax-temp-#{ident}"
62
- }
63
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
64
- body = RedCloth.new(body_text).to_html
65
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
66
- end
67
- stat = File.stat(src)
68
- created = stat.ctime
69
- modified = stat.mtime
70
-
71
- $stdout << template.result(binding)
@@ -1,21 +0,0 @@
1
- begin
2
- require 'spec'
3
- rescue LoadError
4
- require 'rubygems'
5
- require 'spec'
6
- end
7
- begin
8
- require 'spec/rake/spectask'
9
- rescue LoadError
10
- puts <<-EOS
11
- To use rspec for testing you must install rspec gem:
12
- gem install rspec
13
- EOS
14
- exit(0)
15
- end
16
-
17
- desc "Run the specs under spec/models"
18
- Spec::Rake::SpecTask.new do |t|
19
- t.spec_opts = ['--options', "spec/spec.opts"]
20
- t.spec_files = FileList['spec/**/*_spec.rb']
21
- end
@@ -1,11 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestCsv-mapper < Test::Unit::TestCase
4
-
5
- def setup
6
- end
7
-
8
- def test_truth
9
- assert true
10
- end
11
- end
@@ -1,3 +0,0 @@
1
- require 'stringio'
2
- require 'test/unit'
3
- require File.dirname(__FILE__) + '/../lib/csv-mapper'
@@ -1,137 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <meta name="verify-v1" content="VP4WBfIIAPFHiYFYFOAmbwXfPtWF4DrWkzI91Z9JAwI=" />
6
- <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
7
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
- <title>
9
- CSV Mapper
10
- </title>
11
- <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
12
- <style>
13
-
14
- </style>
15
- <script type="text/javascript">
16
- window.onload = function() {
17
- settings = {
18
- tl: { radius: 10 },
19
- tr: { radius: 10 },
20
- bl: { radius: 10 },
21
- br: { radius: 10 },
22
- antiAlias: true,
23
- autoPad: true,
24
- validTags: ["div"]
25
- }
26
- var versionBox = new curvyCorners(settings, document.getElementById("version"));
27
- versionBox.applyCornersToAll();
28
- }
29
- </script>
30
- </head>
31
- <body>
32
- <div id="main">
33
-
34
- <h1>CSV Mapper</h1>
35
- <div class="sidebar">
36
- <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/csv-mapper"; return false'>
37
- <p>Get Version</p>
38
- <a href="http://rubyforge.org/projects/csv-mapper" class="numbers">0.0.4</a>
39
- </div>
40
- </div>
41
- <h2>What</h2>
42
- <p>CsvMapper is a small library intended to simplify the common steps involved with importing <span class="caps">CSV</span> files to a usable form in Ruby.</p>
43
- <h2>Installing</h2>
44
- <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">csv</span><span class="punct">-</span><span class="ident">mapper</span></pre></p>
45
- <h2>The basics</h2>
46
- <p><span class="caps">CSV</span> Mapper makes it easy to import data from <span class="caps">CSV</span> files directly to a collection of any type of Ruby object.<br />
47
- The simplest way to create mappings is declare the names of the attributes in the order corresponding to the <span class="caps">CSV</span> file column order. For more complex mappings you can assign lambdas or methods to be used to convert data from the <span class="caps">CSV</span> row to the value of the declared attribute.</p>
48
- <p>See <a href="rdoc">CsvMapper RDoc</a> for detailed mapping examples.</p>
49
- <h2>Demonstration of usage</h2>
50
- <h3>Example <span class="caps">CSV</span> File Structure</h3>
51
- <pre>
52
- First Name,Last Name,Age
53
- John,Doe,27
54
- Jane,Doe,26
55
- Bat,Man,52
56
- ...etc...
57
- </pre>
58
- <h3>Simple Usage Example</h3>
59
- <p><pre class='syntax'>
60
- <span class="ident">require</span> <span class="punct">'</span><span class="string">csv-mapper</span><span class="punct">'</span>
61
-
62
- <span class="ident">include</span> <span class="constant">CsvMapper</span>
63
-
64
- <span class="ident">results</span> <span class="punct">=</span> <span class="ident">import</span><span class="punct">('</span><span class="string">/path/to/file.csv</span><span class="punct">')</span> <span class="keyword">do</span>
65
- <span class="ident">start_at_row</span> <span class="number">1</span>
66
- <span class="punct">[</span><span class="ident">first_name</span><span class="punct">,</span> <span class="ident">last_name</span><span class="punct">,</span> <span class="ident">age</span><span class="punct">]</span>
67
- <span class="keyword">end</span>
68
-
69
- <span class="ident">results</span><span class="punct">.</span><span class="ident">first</span><span class="punct">.</span><span class="ident">first_name</span> <span class="comment"># John</span>
70
- <span class="ident">results</span><span class="punct">.</span><span class="ident">first</span><span class="punct">.</span><span class="ident">last_name</span> <span class="comment"># Doe</span>
71
- <span class="ident">results</span><span class="punct">.</span><span class="ident">first</span><span class="punct">.</span><span class="ident">age</span> <span class="comment"># 27</span>
72
- </pre></p>
73
- <h3>Automagical Attribute Discovery Example</h3>
74
- <p><pre class='syntax'>
75
- <span class="ident">include</span> <span class="constant">CsvMapper</span>
76
-
77
- <span class="ident">results</span> <span class="punct">=</span> <span class="ident">import</span><span class="punct">('</span><span class="string">/path/to/file.csv</span><span class="punct">')</span> <span class="keyword">do</span>
78
- <span class="ident">read_attributes_from_file</span>
79
- <span class="keyword">end</span>
80
-
81
- <span class="ident">results</span><span class="punct">.</span><span class="ident">first</span><span class="punct">.</span><span class="ident">first_name</span> <span class="comment"># John</span>
82
- <span class="ident">results</span><span class="punct">.</span><span class="ident">first</span><span class="punct">.</span><span class="ident">last_name</span> <span class="comment"># Doe</span>
83
- <span class="ident">results</span><span class="punct">.</span><span class="ident">first</span><span class="punct">.</span><span class="ident">age</span> <span class="comment"># 27</span>
84
- </pre></p>
85
- <h3>Import to ActiveRecord Example</h3>
86
- <p>Although <span class="caps">CSV</span> Mapper has no dependency on ActiveRecord; it‘s easy to import a <span class="caps">CSV</span> file to ActiveRecord models and save them.</p>
87
- <p><pre class='syntax'>
88
- <span class="ident">require</span> <span class="punct">'</span><span class="string">csv-mapper</span><span class="punct">'</span>
89
-
90
- <span class="comment"># Define an ActiveRecord model</span>
91
- <span class="keyword">class </span><span class="class">Person</span> <span class="punct">&lt;</span> <span class="constant">ActiveRecord</span><span class="punct">::</span><span class="constant">Base</span><span class="punct">;</span> <span class="keyword">end</span>
92
-
93
- <span class="ident">include</span> <span class="constant">CsvMapper</span>
94
-
95
- <span class="ident">results</span> <span class="punct">=</span> <span class="ident">import</span><span class="punct">('</span><span class="string">/path/to/file.csv</span><span class="punct">')</span> <span class="keyword">do</span>
96
- <span class="ident">map_to</span> <span class="constant">Person</span> <span class="comment"># Map to the Person ActiveRecord class (defined above) instead of the default OpenStruct.</span>
97
- <span class="ident">after_row</span> <span class="ident">lambda</span><span class="punct">{|</span><span class="ident">row</span><span class="punct">,</span> <span class="ident">person</span><span class="punct">|</span> <span class="ident">person</span><span class="punct">.</span><span class="ident">save</span> <span class="punct">}</span> <span class="comment"># Call this lambda and save each record after it's parsed.</span>
98
-
99
- <span class="ident">start_at_row</span> <span class="number">1</span>
100
- <span class="punct">[</span><span class="ident">first_name</span><span class="punct">,</span> <span class="ident">last_name</span><span class="punct">,</span> <span class="ident">age</span><span class="punct">]</span>
101
- <span class="keyword">end</span>
102
- </pre></p>
103
- <h2>Forum</h2>
104
- <p><a href="http://groups.google.com/group/csv-mapper">http://groups.google.com/group/csv-mapper</a></p>
105
- <h2>How to submit patches</h2>
106
- <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
107
- <p>You can fetch the source from:</p>
108
- <ul>
109
- <li>github: <a href="http://github.com/pillowfactory/csv-mapper/tree/master">http://github.com/pillowfactory/csv-mapper/tree/master</a></li>
110
- </ul>
111
- <pre>git clone git://github.com/pillowfactory/csv-mapper.git</pre>
112
- <h3>Build and test instructions</h3>
113
- <pre>cd csv-mapper
114
- rake test
115
- rake install_gem</pre>
116
- <h2>License</h2>
117
- <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
118
- <h2>Contact</h2>
119
- <p>Comments are welcome. Send an email to <a href="mailto:lpillow@gmail.com">Luke Pillow</a> email via the <a href="http://groups.google.com/group/csv-mapper">forum</a></p>
120
- <p class="coda">
121
- <a href="http://www.pillowfactory.org">Luke Pillow</a>, 5th August 2009<br>
122
- Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
123
- </p>
124
- </div>
125
-
126
- <!-- insert site tracking codes here, like Google Urchin -->
127
- <script type="text/javascript">
128
- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
129
- document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
130
- </script>
131
- <script type="text/javascript">
132
- try {
133
- var pageTracker = _gat._getTracker("UA-6579393-1");
134
- pageTracker._trackPageview();
135
- } catch(err) {}</script>
136
- </body>
137
- </html>