active_report 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +89 -2
- data/lib/active_report/hash.rb +1 -1
- data/lib/active_report/version.rb +1 -1
- 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: 5e0e8dfb9bb0e6810b9fd537cfb16338779cb7e0
|
4
|
+
data.tar.gz: 594f7f35558125e75eb6ae3bbef45f558b040ece
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4320dcdb89c7069b60561c830f796c2d8e22f77a2e7bae8efb93a529b8d8c5e9757af4526f011492081bbe3863388b86857b00475e23c54dbf9a49d8792d8f6
|
7
|
+
data.tar.gz: e216ccd01842c9c116af5392adb4a02eb613fc77e670abeafaeec699501811a56a36312a287295934251317798bba2e0cd6c4bc1982f5a8f9b7eb9563f5887f8
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# ActiveReport
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/active_report.svg)](http://badge.fury.io/rb/active_report)
|
4
|
+
[![Build Status](https://travis-ci.org/drexed/active_report.svg?branch=master)](https://travis-ci.org/drexed/active_report)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/drexed/active_report/badge.png)](https://coveralls.io/r/drexed/active_report)
|
6
|
+
|
7
|
+
ActiveReport is a library to export CSV's out of arrays, hashes, and records and vice versa.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -20,7 +24,90 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
23
|
-
|
27
|
+
### Array
|
28
|
+
|
29
|
+
**Export:** Convert an array or array of arrays to a CSV.
|
30
|
+
|
31
|
+
**Options:**
|
32
|
+
* headers: column titles of CSV data
|
33
|
+
* options: CSV options to be use on generation
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
@list = [
|
37
|
+
[1, "Lorem lipsum etc...", true],
|
38
|
+
[2, "Xorem lipsum etc...", false],
|
39
|
+
[3, "Porem lipsum etc...", true]
|
40
|
+
]
|
41
|
+
|
42
|
+
ActiveReport::Array.export(@list)
|
43
|
+
ActiveReport::Array.export(@list, headers: ["ID", "Task", "Completed"], options: { col_sep: ";" })
|
44
|
+
```
|
45
|
+
|
46
|
+
**Import:** Convert a CSV into an array or array of arrays.
|
47
|
+
|
48
|
+
**Options:**
|
49
|
+
* headers: column titles of array data
|
50
|
+
* options: CSV options to be use on parsing
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
ActiveReport::Array.import("sample.csv")
|
54
|
+
ActiveReport::Array.import("sample.csv", headers: ["ID", "Task", "Completed"], options: { col_sep: ";" })
|
55
|
+
```
|
56
|
+
|
57
|
+
### Hash
|
58
|
+
|
59
|
+
**Export:** Convert a hash or an array of hashes to a CSV.
|
60
|
+
|
61
|
+
**Options:**
|
62
|
+
* only: key/value pairs to be used on generation
|
63
|
+
* except: key/value pairs not to be used on generation
|
64
|
+
* headers: column titles of CSV data
|
65
|
+
* options: CSV options to be use on generation
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
@list = [
|
69
|
+
{ id: 1, item: "Lorem lipsum etc...", completed: true},
|
70
|
+
{ id: 2, item: "Xorem lipsum etc...", completed: false},
|
71
|
+
{ id: 3, item: "Porem lipsum etc...", completed: true}
|
72
|
+
]
|
73
|
+
|
74
|
+
ActiveReport::Hash.export(@list)
|
75
|
+
ActiveReport::Hash.export(@list, only: [:id, :item], headers: ["ID", "Task"], options: { col_sep: ";" })
|
76
|
+
```
|
77
|
+
|
78
|
+
**Import:** Convert a CSV into an array of hashes.
|
79
|
+
|
80
|
+
**Options:**
|
81
|
+
* only: key/value pairs to be used on generation
|
82
|
+
* except: key/value pairs not to be used on generation
|
83
|
+
* headers: column titles of CSV data **Required**
|
84
|
+
* options: CSV options to be use on parsing
|
85
|
+
|
86
|
+
```ruby
|
87
|
+
ActiveReport::Hash.import("sample.csv")
|
88
|
+
ActiveReport::Hash.import("sample.csv", except: :completed, headers: ["ID", "Task"], options: { col_sep: ";" })
|
89
|
+
```
|
90
|
+
|
91
|
+
### Record
|
92
|
+
|
93
|
+
**Export:** Convert an ActiveRecord/Relation object(s) to a CSV.
|
94
|
+
|
95
|
+
**Options:**
|
96
|
+
* only: columns to be used on generation
|
97
|
+
* except: columns not to be used on generation
|
98
|
+
* headers: column titles of CSV data
|
99
|
+
* options: CSV options to be use on generation
|
100
|
+
|
101
|
+
```ruby
|
102
|
+
@list = [
|
103
|
+
<# ActiveRecord::Relation Object >,
|
104
|
+
<# ActiveRecord::Relation Object >,
|
105
|
+
<# ActiveRecord::Relation Object >
|
106
|
+
]
|
107
|
+
|
108
|
+
ActiveReport::Record.export(@list)
|
109
|
+
ActiveReport::Record.export(@list, only: [:id, :item], headers: ["ID", "Task"], options: { col_sep: ";" })
|
110
|
+
```
|
24
111
|
|
25
112
|
## Contributing
|
26
113
|
|
data/lib/active_report/hash.rb
CHANGED
@@ -46,7 +46,7 @@ class ActiveReport::Hash
|
|
46
46
|
CSV.foreach(@datum, @options) do |data|
|
47
47
|
processed_data = {}
|
48
48
|
@headers.each_with_index do |v,i|
|
49
|
-
processed_data.store(v.gsub(" ", "_").downcase.to_sym, data.fetch(i, nil) )
|
49
|
+
processed_data.store(v.to_s.gsub(" ", "_").downcase.to_sym, data.fetch(i, nil) )
|
50
50
|
end
|
51
51
|
|
52
52
|
processed_data.keep_if { |k,v| @only.include?(k) } unless @only.empty?
|