simple-excel-import 0.0.2 → 0.0.2.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 +4 -4
- data/README.md +23 -18
- data/lib/simple-excel-import.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8a7e465f7acc18f1a2f7bd0b7d2a64d265303f5
|
4
|
+
data.tar.gz: 907d3c025a1fd93ed5926cc1ef3c0ff29d943f1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 902a4dad2473850f8e1d1a00da5237ecf54f008e719a7fec1f9a5ff45bd97645602903fb3dc216f394562f4931228b9164d994665c43c6ad20ccfab8ad265d1e
|
7
|
+
data.tar.gz: 81cca5a831821c849ac136f50a8fe5db083ac3aefc9821776f56b2536451f4504cb994d7a13610353342d00d63767eb892ee91edd493e4e6ccc4547552c2cfbf
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
simple-excel-import
|
2
2
|
===================
|
3
3
|
|
4
|
+
[](https://travis-ci.org/mindpin/simple-excel-import)
|
5
|
+
[](https://coveralls.io/r/mindpin/simple-excel-import)
|
6
|
+
[](https://codeclimate.com/github/mindpin/simple-excel-import)
|
7
|
+
|
4
8
|
|
5
9
|
## Target
|
6
10
|
Get data from excel file and save into database model
|
@@ -18,38 +22,39 @@ include in Gemfile:
|
|
18
22
|
gem 'simple-excel-import'
|
19
23
|
```
|
20
24
|
|
21
|
-
## How
|
25
|
+
## How to use
|
26
|
+
|
27
|
+
in a model
|
22
28
|
|
23
29
|
```ruby
|
24
|
-
|
25
|
-
|
26
|
-
simple_excel_import :teacher, :fields => [:tid, :age, :gender, :nation]
|
27
|
-
:default => {
|
28
|
-
:role => :teacher
|
29
|
-
}
|
30
|
+
class Book < ActiveRecord::Base
|
31
|
+
simple_excel_import :common, :fields => [:title, :price, :kind]
|
30
32
|
|
31
|
-
simple_excel_import :
|
33
|
+
simple_excel_import :program, :fields => [:title, :price, :url],
|
32
34
|
:default => {
|
33
|
-
:
|
35
|
+
:kind => '编程'
|
34
36
|
}
|
35
37
|
end
|
38
|
+
```
|
36
39
|
|
40
|
+
then, you can call Model.parse_excel_xxx
|
37
41
|
|
38
|
-
|
42
|
+
```ruby
|
39
43
|
# parse excel file without saving
|
40
|
-
|
41
|
-
# -> return
|
42
|
-
|
44
|
+
Book.parse_excel_common(excel_file)
|
45
|
+
# -> return a array of <#Book> with fields title, price, kind filled
|
43
46
|
|
44
|
-
|
45
|
-
|
47
|
+
Book.parse_excel_program(excel_file)
|
48
|
+
# -> return a array of <#Book> with fields title, price, url filled, and kind of default value '编程'
|
49
|
+
```
|
46
50
|
|
47
|
-
|
48
|
-
User.get_sample_excel_teacher
|
51
|
+
you can call Model.import_excel_xxx to save models into database
|
49
52
|
|
53
|
+
```ruby
|
54
|
+
Book.parse_excel_common(excel_file)
|
55
|
+
Book.parse_excel_program(excel_file)
|
50
56
|
```
|
51
57
|
|
52
|
-
|
53
58
|
## TODO
|
54
59
|
- support nil field in field list
|
55
60
|
:fields => [:tid, nil, :gender, :nation]
|
data/lib/simple-excel-import.rb
CHANGED