honey_format 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 582322cb2da52ea080c388d8112159bf2f7923e3
4
- data.tar.gz: e6854e04c23c2aa129753bf373c9417df4887627
3
+ metadata.gz: 3ba71ccfedf80d0f721f3b205a6eb8f247284704
4
+ data.tar.gz: e6091ac68245db3e1c1d0918e9aed66361b38a5e
5
5
  SHA512:
6
- metadata.gz: 324f80c7fb803942428dfd051e55de92e687d83b7c6c5f351330f4eb159260f34fb6fb4a7b695d64c4ccdebd2a8e96aa90acb338f95645dd29b188a61dec09e0
7
- data.tar.gz: 9d5e5f4724f1aca4f8676f1814d3034709d40c26f5266781d6ab7f62150f0bffaf797961090aebb7f579b950d8f8a25b1fae62526eecc43d73fbc82ba804a17f
6
+ metadata.gz: 918906a7bdfc3d6ef900794832a8359811ee69ea9c68ab8a563bc5199308db91637fa8610f7b265bc7ddbcad13a3f74b1e6f467df5247eb0ed2d022bd9ce1bf2
7
+ data.tar.gz: 4f46d54f77c109349131ea3c3db982e1671aa3597ea1383b3cd7b6176a64d72bb0650fe0b772fa3542883c38761589344c23fb510ec110e21ce15a80d7845819
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ benchmark.csv
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Jacob Burenstam
3
+ Copyright (c) 2015 Jacob Burenstam Linder
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
- # HoneyFormat
1
+ # HoneyFormat [![Build Status](https://travis-ci.org/buren/honey_format.svg)](https://travis-ci.org/buren/honey_format) [![Code Climate](https://codeclimate.com/github/buren/honey_format/badges/gpa.svg)](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 'honey-import'
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 honey-import
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
- _Note_: This gem, as you can imagine, adds some overhead to parsing a CSV string. Make sure to benchmark before using this for something performance sensitive.
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/honey-import. 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.
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
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module HoneyFormat
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
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.0
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-01 00:00:00.000000000 Z
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