honey_format 0.1.0 → 0.1.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/.gitignore +1 -0
- data/LICENSE.txt +1 -1
- data/README.md +26 -5
- data/benchmark.rb +17 -0
- data/lib/honey_format/csv.rb +2 -2
- data/lib/honey_format/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ba71ccfedf80d0f721f3b205a6eb8f247284704
|
4
|
+
data.tar.gz: e6091ac68245db3e1c1d0918e9aed66361b38a5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 918906a7bdfc3d6ef900794832a8359811ee69ea9c68ab8a563bc5199308db91637fa8610f7b265bc7ddbcad13a3f74b1e6f467df5247eb0ed2d022bd9ce1bf2
|
7
|
+
data.tar.gz: 4f46d54f77c109349131ea3c3db982e1671aa3597ea1383b3cd7b6176a64d72bb0650fe0b772fa3542883c38761589344c23fb510ec110e21ce15a80d7845819
|
data/.gitignore
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
# HoneyFormat
|
1
|
+
# HoneyFormat [](https://travis-ci.org/buren/honey_format) [](https://codeclimate.com/github/buren/honey_format)
|
2
2
|
|
3
3
|
Convert CSV to object with one command.
|
4
4
|
|
5
|
+
Perfect for small files of test data or small import scripts.
|
6
|
+
|
5
7
|
```ruby
|
6
8
|
csv_string = "Id, Username\n 1, buren"
|
7
9
|
csv = HoneyFormat::CSV.new(csv_string)
|
@@ -16,7 +18,7 @@ user.username # => "buren"
|
|
16
18
|
Add this line to your application's Gemfile:
|
17
19
|
|
18
20
|
```ruby
|
19
|
-
gem '
|
21
|
+
gem 'honey_format'
|
20
22
|
```
|
21
23
|
|
22
24
|
And then execute:
|
@@ -26,7 +28,7 @@ $ bundle
|
|
26
28
|
|
27
29
|
Or install it yourself as:
|
28
30
|
```
|
29
|
-
$ gem install
|
31
|
+
$ gem install honey_format
|
30
32
|
```
|
31
33
|
|
32
34
|
## Usage
|
@@ -64,7 +66,26 @@ csv = HoneyCSV.new(csv_string, header: ['Id', 'Username'])
|
|
64
66
|
csv.rows.first.username # => "buren"
|
65
67
|
```
|
66
68
|
|
67
|
-
|
69
|
+
## Benchmark
|
70
|
+
|
71
|
+
_Note_: This gem, adds some overhead to parsing a CSV string. I've included some benchmarks below, your mileage may vary..
|
72
|
+
|
73
|
+
Benchmarks for a 21MB file with 10 columns (MBP 2013 OSX 10.10).
|
74
|
+
|
75
|
+
```
|
76
|
+
Calculating -------------------------------------
|
77
|
+
stdlib CSV 1.000 i/100ms
|
78
|
+
HoneyFormat::CSV 1.000 i/100ms
|
79
|
+
-------------------------------------------------
|
80
|
+
stdlib CSV 0.317 (± 0.0%) i/s - 4.000 in 12.636647s
|
81
|
+
HoneyFormat::CSV 0.335 (± 0.0%) i/s - 4.000 in 12.061301s
|
82
|
+
|
83
|
+
Comparison:
|
84
|
+
HoneyFormat::CSV: 0.3 i/s
|
85
|
+
stdlib CSV: 0.3 i/s - 1.06x slower
|
86
|
+
```
|
87
|
+
|
88
|
+
Run the benchmark as a regular ruby file: `ruby benchmark.rb`.
|
68
89
|
|
69
90
|
## Development
|
70
91
|
|
@@ -74,7 +95,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
74
95
|
|
75
96
|
## Contributing
|
76
97
|
|
77
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/buren/
|
98
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/buren/honey_format. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
78
99
|
|
79
100
|
|
80
101
|
## License
|
data/benchmark.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'benchmark/ips'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'honey_format'
|
6
|
+
|
7
|
+
csv = File.read('benchmark.csv')
|
8
|
+
|
9
|
+
Benchmark.ips do |x|
|
10
|
+
x.time = 10
|
11
|
+
x.warmup = 2
|
12
|
+
|
13
|
+
x.report("stdlib CSV") { CSV.parse(csv) }
|
14
|
+
x.report("HoneyFormat::CSV") { HoneyFormat::CSV.new(csv) }
|
15
|
+
|
16
|
+
x.compare!
|
17
|
+
end
|
data/lib/honey_format/csv.rb
CHANGED
@@ -7,8 +7,8 @@ module HoneyFormat
|
|
7
7
|
class CSV
|
8
8
|
attr_reader :header, :columns
|
9
9
|
|
10
|
-
def initialize(csv, header: nil, valid_columns: :all)
|
11
|
-
csv = ::CSV.parse(csv)
|
10
|
+
def initialize(csv, delimiter: ',', header: nil, valid_columns: :all)
|
11
|
+
csv = ::CSV.parse(csv, col_sep: delimiter)
|
12
12
|
@head = build_header(header || csv.shift)
|
13
13
|
@csv_body = csv
|
14
14
|
@columns = build_columns(@head, valid_columns)
|
data/lib/honey_format/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: honey_format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Burenstam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- LICENSE.txt
|
83
83
|
- README.md
|
84
84
|
- Rakefile
|
85
|
+
- benchmark.rb
|
85
86
|
- bin/console
|
86
87
|
- bin/setup
|
87
88
|
- honey_format.gemspec
|