csv_import_ruby 0.0.1
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.
- checksums.yaml +7 -0
- data/lib/csv_import_ruby.rb +24 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9c494450410deb0d39f51538c7ada5d5ae726ddf
|
4
|
+
data.tar.gz: 2fd7568f702c4105ba935271132cfa2bcf6a56bb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3f127be3e67ca8ce4e823588345f501e2c3dd596de753ecf74d266e9ceb0e5161627415353cd949bc1b1fc1f2b269d7142e459e4636e2cad8ea99058077cef3
|
7
|
+
data.tar.gz: cce557f9d9bf8d71024954f001f15f5f30c396b7938adefaffeaa1160914d7342a3da2d2edf89d915e7b72f20d559ece1e95b39330a49c9db88b91b5b42d734e
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
def import_row(row, columns, options)
|
4
|
+
values = Hash[columns.zip(row)]
|
5
|
+
attributes = values.select{ |key, value| self.column_names.include?(key.to_s) }
|
6
|
+
attributes.each{ |key, value| attributes[key] = value.strip } if options[:remove_whitespace]
|
7
|
+
self.create(attributes)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_importer(*columns, options)
|
11
|
+
self.instance_eval do
|
12
|
+
define_singleton_method(:import!) do |csv|
|
13
|
+
CSV.parse(csv) do |row|
|
14
|
+
import_row(row, columns, options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
define_singleton_method(:import_file!) do |file_name|
|
19
|
+
CSV.foreach(file_name) do |row|
|
20
|
+
import_row(row, columns, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: csv_import_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Amanda Chang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Parse CSV spreadsheets into ActiveRecord objects
|
14
|
+
email: amanda.chang10@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/csv_import_ruby.rb
|
20
|
+
homepage: http://rubygems.org/gems/csv_import_ruby
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Import CSV to ActiveRecord
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|