honey_format 0.11.0 → 0.12.0
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/CHANGELOG.md +5 -0
- data/README.md +13 -0
- data/bin/benchmark +64 -8
- data/exe/honey_format +11 -1
- data/lib/honey_format/csv.rb +1 -0
- data/lib/honey_format/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d236d3a0eeee26825fc307504a6e65c66dbd30c5cbc8b4d190f5af391e73fc0
|
4
|
+
data.tar.gz: e5989adcda923101ccff44d34b15adffe7db4cbd1cabdfad3229dace94076c6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fa617674f689a27707c15a6a9d307181a8bda8662da9f40e5a3a689821c1269ca34762c4609511a7265cf75c04e551c1e1de8d5e2d0825826ff6a422aa77398
|
7
|
+
data.tar.gz: de36bd4aa3bd05e3e9f99d703b0ffe4674f894edaa85aecc3b51114f434dcdf9d6ea3b23c9b3b2b0c0c5319d63849c49532d46bcccb044ebc4190c77c9212eeb
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -8,6 +8,7 @@ Convert CSV to an array of objects with with ease.
|
|
8
8
|
- Convert column values with custom row builder
|
9
9
|
- Convert header column names
|
10
10
|
- Customize what columns and rows are included in CSV output
|
11
|
+
- [CLI](#cli)
|
11
12
|
- Has no dependencies other than Ruby stdlib
|
12
13
|
- Supports Ruby >= 2.3
|
13
14
|
|
@@ -185,6 +186,18 @@ You can see all [available errors here](https://www.rubydoc.info/gems/honey_form
|
|
185
186
|
|
186
187
|
If you want to see more usage examples check out the `spec/` directory.
|
187
188
|
|
189
|
+
## CLI
|
190
|
+
|
191
|
+
```
|
192
|
+
Usage: honey_format [file.csv] [options]
|
193
|
+
--csv=input.csv CSV file
|
194
|
+
--columns=id,name Select columns.
|
195
|
+
--output=output.csv CSV output (STDOUT otherwise)
|
196
|
+
--delimiter=, CSV delimiter (default: ,)
|
197
|
+
-h, --help How to use
|
198
|
+
--version Show version
|
199
|
+
```
|
200
|
+
|
188
201
|
## Benchmark
|
189
202
|
|
190
203
|
_Note_: This gem, adds some overhead to parsing a CSV string. I've included some benchmarks below, your mileage may vary..
|
data/bin/benchmark
CHANGED
@@ -4,16 +4,72 @@ require 'honey_format'
|
|
4
4
|
|
5
5
|
require 'benchmark/ips'
|
6
6
|
require 'csv'
|
7
|
+
require 'optparse'
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
input_path = nil
|
10
|
+
benchmark_time = 30
|
11
|
+
benchmark_warmup = 5
|
12
|
+
lines_multipliers = [1]
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
OptionParser.new do |parser|
|
15
|
+
parser.banner = "Usage: bin/benchmark [file.csv] [options]"
|
16
|
+
parser.default_argv = ARGV
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
parser.on("--csv=file1.csv", String, "CSV file(s)") do |value|
|
19
|
+
input_path = value
|
20
|
+
end
|
17
21
|
|
18
|
-
|
22
|
+
parser.on("--lines-multipliers=[1,10,50]", Array, "Multiply the rows in the CSV file (default: 1)") do |value|
|
23
|
+
lines_multipliers = value.map do |v|
|
24
|
+
Integer(v).tap do |int|
|
25
|
+
unless int >= 1
|
26
|
+
raise(ArgumentError, '--lines-multiplier must be 1 or greater')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
parser.on("--time=[30]", String, "Benchmark time (default: 30)") do |value|
|
33
|
+
benchmark_time = Integer(value)
|
34
|
+
end
|
35
|
+
|
36
|
+
parser.on("--warmup=[30]", String, "Benchmark warmup (default: 30)") do |value|
|
37
|
+
benchmark_warmup = Integer(value)
|
38
|
+
end
|
39
|
+
|
40
|
+
parser.on("-h", "--help", "How to use") do
|
41
|
+
puts parser
|
42
|
+
exit
|
43
|
+
end
|
44
|
+
|
45
|
+
# No argument, shows at tail. This will print an options summary.
|
46
|
+
parser.on_tail("-h", "--help", "Show this message") do
|
47
|
+
puts parser
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
end.parse!
|
51
|
+
|
52
|
+
csv = File.read(input_path)
|
53
|
+
|
54
|
+
lines_multipliers.each do |lines_multiplier|
|
55
|
+
if lines_multiplier > 1
|
56
|
+
orignial_csv_lines = csv.lines
|
57
|
+
rows = orignial_csv_lines[1..-1] * lines_multiplier
|
58
|
+
csv = orignial_csv_lines.first + rows.join
|
59
|
+
end
|
60
|
+
|
61
|
+
line_count = csv.lines.length
|
62
|
+
|
63
|
+
puts "== [START] Benchmark for #{line_count} lines =="
|
64
|
+
Benchmark.ips do |x|
|
65
|
+
x.time = benchmark_time
|
66
|
+
x.warmup = benchmark_warmup
|
67
|
+
|
68
|
+
x.report('stdlib CSV no options') { CSV.parse(csv) }
|
69
|
+
x.report('stdlib CSV with header') { CSV.parse(csv, headers: true) }
|
70
|
+
x.report('HoneyFormat::CSV') { HoneyFormat::CSV.new(csv).rows }
|
71
|
+
|
72
|
+
x.compare!
|
73
|
+
end
|
74
|
+
puts "== [END] Benchmark for #{line_count} lines =="
|
19
75
|
end
|
data/exe/honey_format
CHANGED
@@ -9,6 +9,7 @@ input_path = ARGV.first
|
|
9
9
|
columns = nil
|
10
10
|
output_path = nil
|
11
11
|
delimiter = ','
|
12
|
+
header_only = false
|
12
13
|
|
13
14
|
require 'optparse'
|
14
15
|
|
@@ -20,6 +21,10 @@ OptionParser.new do |parser|
|
|
20
21
|
input_path = value
|
21
22
|
end
|
22
23
|
|
24
|
+
parser.on("--[no-]only-header=[output.csv]", "Print only the header") do |value|
|
25
|
+
header_only = value
|
26
|
+
end
|
27
|
+
|
23
28
|
parser.on("--columns=id,name", Array, "Select columns.") do |value|
|
24
29
|
columns = value
|
25
30
|
end
|
@@ -50,7 +55,12 @@ OptionParser.new do |parser|
|
|
50
55
|
end.parse!
|
51
56
|
|
52
57
|
csv = HoneyFormat::CSV.new(File.read(input_path), delimiter: delimiter)
|
53
|
-
|
58
|
+
if header_only
|
59
|
+
puts csv.columns.join(',')
|
60
|
+
exit
|
61
|
+
end
|
62
|
+
|
63
|
+
csv_string = csv.to_csv(columns: columns&.map(&:to_sym))
|
54
64
|
if output_path
|
55
65
|
File.write(output_path, csv_string)
|
56
66
|
else
|
data/lib/honey_format/csv.rb
CHANGED
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.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Burenstam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|