honey_format 0.18.0 → 0.19.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/.travis.yml +27 -6
- data/CHANGELOG.md +12 -0
- data/README.md +18 -4
- data/exe/honey_format +7 -1
- data/lib/honey_format/cli/cli.rb +8 -0
- data/lib/honey_format/configuration.rb +1 -0
- data/lib/honey_format/converters/header_column_converter.rb +34 -21
- data/lib/honey_format/helpers/helpers.rb +1 -0
- data/lib/honey_format/matrix/header.rb +1 -0
- data/lib/honey_format/matrix/row_builder.rb +2 -0
- data/lib/honey_format/matrix/rows.rb +1 -0
- data/lib/honey_format/registry.rb +4 -1
- 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: cf04ea671d5bdbe82a40c6c755e0f975a4326e3f803cc380cbfb513bcb7587d1
|
4
|
+
data.tar.gz: 14893ca65e6ecb420fac9e4a4783d2ab2267d2b63b492a70c297ca51e66bf711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9a89819d1d40b99af14bbc1c0b5df765d5c91ab7c1146f39f8b6dd04796d718251280b6b31b3dc61e14ba413f46d9edb9e7e8a1aa1c308531d20cfdb0c5bb9b
|
7
|
+
data.tar.gz: b23f67d3df21ca3a01d03c7054502aa0a60d2819717f770db3a30edccdf597b9a9943b7107515e1e454156625c5d1aa3efcd918772b0dcbc5b9b85298ed71fe8
|
data/.travis.yml
CHANGED
@@ -1,7 +1,28 @@
|
|
1
1
|
language: ruby
|
2
|
-
|
3
|
-
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
script:
|
3
|
+
- bundle exec rspec
|
4
|
+
matrix:
|
5
|
+
fast_finish: true
|
6
|
+
allow_failures:
|
7
|
+
- name: TruffleRuby
|
8
|
+
rvm: system
|
9
|
+
include:
|
10
|
+
- rvm: 2.3.0
|
11
|
+
install:
|
12
|
+
- gem install bundler --no-ri --no-rdoc
|
13
|
+
- bundle install
|
14
|
+
- rvm: 2.5.1
|
15
|
+
install:
|
16
|
+
- gem install bundler --no-ri --no-rdoc
|
17
|
+
- bundle install
|
18
|
+
- rvm: 2.6.0-preview3
|
19
|
+
install:
|
20
|
+
- bundle install
|
21
|
+
- name: TruffleRuby
|
22
|
+
rvm: system
|
23
|
+
install:
|
24
|
+
- export TRUFFLERUBY_VERSION=1.0.0-rc3
|
25
|
+
- curl -L https://github.com/oracle/truffleruby/releases/download/vm-$TRUFFLERUBY_VERSION/truffleruby-$TRUFFLERUBY_VERSION-linux-amd64.tar.gz | tar xz
|
26
|
+
- export PATH="$PWD/truffleruby-$TRUFFLERUBY_VERSION-linux-amd64/bin:$PATH"
|
27
|
+
- gem install bundler -v 1.16.6 --no-ri --no-rdoc
|
28
|
+
- bundle install
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# HEAD
|
2
2
|
|
3
|
+
## v0.19.0
|
4
|
+
|
5
|
+
* Add `method_name` as alias for `header_column` converter
|
6
|
+
* Freeze constants in `HeaderColumnConverter`
|
7
|
+
* Add support for passing a callable object in `type_map` argument [PR#49](https://github.com/buren/honey_format/pull/49)
|
8
|
+
* Remove non-printable & zero-width characters from header columns
|
9
|
+
* Add `£` to header separator character list
|
10
|
+
* Replace `@` with `_at_` in header converter
|
11
|
+
* Replace all space like chars in Header converter. Closes [Issue#39]([PR#49](https://github.com/buren/honey_format/issues/39))
|
12
|
+
* Improved CLI output when input path is missing
|
13
|
+
|
14
|
+
## v0.18.0
|
3
15
|
|
4
16
|
* Require `set` class in `ConvertBoolean` - fixes crash when set is already required in environment
|
5
17
|
* Allow symbols to be passed to `HeaderColumnConverter`
|
data/README.md
CHANGED
@@ -28,7 +28,8 @@ Id,Username,Email
|
|
28
28
|
CSV
|
29
29
|
csv = HoneyFormat::CSV.new(csv_string, type_map: { id: :integer })
|
30
30
|
csv.columns # => [:id, :username]
|
31
|
-
|
31
|
+
csv.rows # => [#<Row id=1, username="buren">]
|
32
|
+
user = csv.rows.first
|
32
33
|
user.id # => 1
|
33
34
|
user.username # => "buren"
|
34
35
|
|
@@ -98,7 +99,15 @@ csv = HoneyFormat::CSV.new(csv_string, type_map: type_map)
|
|
98
99
|
csv.rows.first.id # => 1
|
99
100
|
```
|
100
101
|
|
101
|
-
|
102
|
+
Pass your own
|
103
|
+
```ruby
|
104
|
+
csv_string = "Id,Username\n1,buren"
|
105
|
+
type_map = { username: proc { |v| v.upcase } }
|
106
|
+
csv = HoneyFormat::CSV.new(csv_string, type_map: type_map)
|
107
|
+
csv.rows.first.username # => "BUREN"
|
108
|
+
```
|
109
|
+
|
110
|
+
Register your own converter
|
102
111
|
```ruby
|
103
112
|
HoneyFormat.configure do |config|
|
104
113
|
config.converter_registry.register :upcased, proc { |v| v.upcase }
|
@@ -125,7 +134,12 @@ decimal_converter = HoneyFormat.converter_registry[:decimal]
|
|
125
134
|
decimal_converter.call('1.1') # => 1.1
|
126
135
|
```
|
127
136
|
|
128
|
-
|
137
|
+
Default converter names
|
138
|
+
```ruby
|
139
|
+
HoneyFormat.config.default_converters.keys
|
140
|
+
```
|
141
|
+
|
142
|
+
See [`Configuration#default_converters`](https://github.com/buren/honey_format/blob/master/lib/honey_format/configuration.rb#L99) for a complete list of the default ones.
|
129
143
|
|
130
144
|
__Row builder__
|
131
145
|
|
@@ -403,7 +417,7 @@ Usage: bin/benchmark [file.csv] [options]
|
|
403
417
|
--[no-]verbose Verbose output
|
404
418
|
--lines-multipliers=[1,2,10] Multiply the rows in the CSV file (default: 1)
|
405
419
|
--time=[30] Benchmark time (default: 30)
|
406
|
-
--warmup=[
|
420
|
+
--warmup=[5] Benchmark warmup (default: 5)
|
407
421
|
-h, --help How to use
|
408
422
|
```
|
409
423
|
|
data/exe/honey_format
CHANGED
@@ -10,7 +10,13 @@ require 'honey_format/cli/cli'
|
|
10
10
|
cli = HoneyFormat::CLI.new
|
11
11
|
options = cli.options
|
12
12
|
|
13
|
-
input_path = options[:input_path]
|
13
|
+
input_path = options[:input_path]
|
14
|
+
unless input_path
|
15
|
+
puts cli.usage
|
16
|
+
puts
|
17
|
+
puts '[ERROR] input path required'
|
18
|
+
exit 1
|
19
|
+
end
|
14
20
|
csv_input = File.read(input_path)
|
15
21
|
csv = HoneyFormat::CSV.new(
|
16
22
|
csv_input,
|
data/lib/honey_format/cli/cli.rb
CHANGED
@@ -12,9 +12,14 @@ module HoneyFormat
|
|
12
12
|
# @return [CLI] the CLI
|
13
13
|
def initialize(argv: ARGV, io: STDOUT)
|
14
14
|
@io = io
|
15
|
+
@parser = nil
|
15
16
|
@options = parse_options(argv: argv.dup)
|
16
17
|
end
|
17
18
|
|
19
|
+
def usage
|
20
|
+
@parser.to_s
|
21
|
+
end
|
22
|
+
|
18
23
|
private
|
19
24
|
|
20
25
|
# Puts to configured IO
|
@@ -38,6 +43,8 @@ module HoneyFormat
|
|
38
43
|
type_map = {}
|
39
44
|
|
40
45
|
OptionParser.new do |parser|
|
46
|
+
@parser = parser
|
47
|
+
|
41
48
|
parser.banner = 'Usage: honey_format [options] <file.csv>'
|
42
49
|
parser.default_argv = argv
|
43
50
|
|
@@ -91,6 +98,7 @@ module HoneyFormat
|
|
91
98
|
if input_path && argv.last
|
92
99
|
raise(ArgumentError, "you can't provide both --csv and <path>")
|
93
100
|
end
|
101
|
+
|
94
102
|
input_path ||= argv.last
|
95
103
|
|
96
104
|
{
|
@@ -4,32 +4,44 @@ module HoneyFormat
|
|
4
4
|
# Header column converter
|
5
5
|
module HeaderColumnConverter
|
6
6
|
# Bracket character matcher
|
7
|
-
BRACKETS = /\(|\[|\{|\)|\]|\}
|
7
|
+
BRACKETS = /\(|\[|\{|\)|\]|\}/.freeze
|
8
8
|
|
9
9
|
# Separator characters
|
10
|
-
SEPS = /'|"
|
10
|
+
SEPS = /'|"|\||\*|\^|\&|%|\$|€|£|#/.freeze
|
11
|
+
|
12
|
+
# Space characters
|
13
|
+
SPACES = /[[:space:]]+/.freeze
|
14
|
+
|
15
|
+
# Non-printable characters
|
16
|
+
NON_PRINT = /[^[:print:]]/.freeze
|
17
|
+
|
18
|
+
# zero-width characters - see https://stackoverflow.com/q/50647999
|
19
|
+
ZERO_WIDTH = /[\u200B-\u200D\uFEFF]/.freeze
|
11
20
|
|
12
21
|
# Replace map
|
13
22
|
REPLACE_MAP = [
|
14
|
-
[/\\/, '/'],
|
15
|
-
[/ \(/, '('],
|
16
|
-
[/ \[/, '['],
|
17
|
-
[/ \{/, '{'],
|
18
|
-
[/ \{/, '{'],
|
19
|
-
[/\) /, ')'],
|
20
|
-
[/\] /, ']'],
|
21
|
-
[/\} /, '}'],
|
22
|
-
[
|
23
|
-
[
|
24
|
-
[
|
25
|
-
[
|
26
|
-
[
|
27
|
-
[
|
28
|
-
[
|
29
|
-
[
|
30
|
-
[
|
31
|
-
[
|
32
|
-
|
23
|
+
[/\\/, '/'], # replace "\" with "/"
|
24
|
+
[/ \(/, '('], # replace " (" with "("
|
25
|
+
[/ \[/, '['], # replace " [" with "["
|
26
|
+
[/ \{/, '{'], # replace " {" with "{"
|
27
|
+
[/ \{/, '{'], # replace " {" with "{"
|
28
|
+
[/\) /, ')'], # replace ") " with ")"
|
29
|
+
[/\] /, ']'], # replace "] " with "]"
|
30
|
+
[/\} /, '}'], # replace "} " with "}"
|
31
|
+
[/@/, '_at_'], # replace "@' with "_at_"
|
32
|
+
[BRACKETS, '_'], # replace (, [, {, ), ] and } with "_"
|
33
|
+
[SPACES, '_'], # replace one or more space chars with "_"
|
34
|
+
[/-/, '_'], # replace "-" with "_"
|
35
|
+
[/\.|,/, '_'], # replace "." and "," with "_"
|
36
|
+
[/::/, '_'], # replace "::" with "_"
|
37
|
+
[%r{/}, '_'], # replace "/" with "_"
|
38
|
+
[SEPS, '_'], # replace separator chars with "_"
|
39
|
+
[/_+/, '_'], # replace one or more "_" with single "_"
|
40
|
+
[NON_PRINT, ''], # remove non-printable characters
|
41
|
+
[ZERO_WIDTH, ''], # remove zero-width characters
|
42
|
+
[/\A_+/, ''], # remove leading "_"
|
43
|
+
[/_+\z/, ''], # remove trailing "_"
|
44
|
+
].map { |e| e.map(&:freeze).freeze }.freeze
|
33
45
|
|
34
46
|
# Returns converted value and mutates the argument.
|
35
47
|
# @return [Symbol] the cleaned header column.
|
@@ -42,6 +54,7 @@ module HoneyFormat
|
|
42
54
|
def self.call(column, index = nil)
|
43
55
|
if column.nil? || column.empty?
|
44
56
|
raise(ArgumentError, "column and column index can't be blank/nil") unless index
|
57
|
+
|
45
58
|
return :"column#{index}"
|
46
59
|
end
|
47
60
|
|
@@ -39,6 +39,7 @@ module HoneyFormat
|
|
39
39
|
build_row!(row)
|
40
40
|
rescue ArgumentError => e
|
41
41
|
raise unless e.message == 'struct size differs'
|
42
|
+
|
42
43
|
raise_invalid_row_length!(e, row)
|
43
44
|
end
|
44
45
|
|
@@ -60,6 +61,7 @@ module HoneyFormat
|
|
60
61
|
end
|
61
62
|
|
62
63
|
return row unless @builder
|
64
|
+
|
63
65
|
@builder.call(row)
|
64
66
|
end
|
65
67
|
|
@@ -38,9 +38,11 @@ module HoneyFormat
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# Call value type
|
41
|
-
# @param [Symbol, String] type the name of the type
|
41
|
+
# @param [Symbol, String, #call] type the name of the type
|
42
42
|
# @param [Object] value to be converted
|
43
43
|
def call(value, type)
|
44
|
+
return type.call(value) if type.respond_to?(:call)
|
45
|
+
|
44
46
|
self[type].call(value)
|
45
47
|
end
|
46
48
|
|
@@ -72,6 +74,7 @@ module HoneyFormat
|
|
72
74
|
# @return [true, false] true if type exists, false otherwise
|
73
75
|
def type?(type)
|
74
76
|
return false unless keyable?(type)
|
77
|
+
|
75
78
|
@callers.key?(to_key(type))
|
76
79
|
end
|
77
80
|
|
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.19.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-
|
11
|
+
date: 2018-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: benchmark-ips
|