honey_format 0.18.0 → 0.19.0

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
  SHA256:
3
- metadata.gz: ab1d4f7975362d7a1e5a63dc5d2709a8859fa8bc2563a616c42dbe181285de28
4
- data.tar.gz: e582e7495778b83d6f1776bbc3048103b3df55ba79d6e6c0383a591e85d768c1
3
+ metadata.gz: cf04ea671d5bdbe82a40c6c755e0f975a4326e3f803cc380cbfb513bcb7587d1
4
+ data.tar.gz: 14893ca65e6ecb420fac9e4a4783d2ab2267d2b63b492a70c297ca51e66bf711
5
5
  SHA512:
6
- metadata.gz: 97a9841215e292ce71e2288ee2d54b01a9befd9ad81fda41e8a0bcc3a34e0b2a045fd4a5b782ea97f6d77820a207e8f3a962a5d8f7c5282db0bff7e37a98c615
7
- data.tar.gz: 00f215cfbee51d5b9f075b32a5e321754753c0f7292f985fccab51983bee6f084eef6409b2d753af37a2a18fcdc9ef71c348063fb0756b36de0122621934addd
6
+ metadata.gz: c9a89819d1d40b99af14bbc1c0b5df765d5c91ab7c1146f39f8b6dd04796d718251280b6b31b3dc61e14ba413f46d9edb9e7e8a1aa1c308531d20cfdb0c5bb9b
7
+ data.tar.gz: b23f67d3df21ca3a01d03c7054502aa0a60d2819717f770db3a30edccdf597b9a9943b7107515e1e454156625c5d1aa3efcd918772b0dcbc5b9b85298ed71fe8
@@ -1,7 +1,28 @@
1
1
  language: ruby
2
- rvm:
3
- - 2.3.0
4
- - 2.4.0
5
- - 2.5.0
6
- - 2.6.0-preview1
7
- before_install: gem install bundler -v 1.16.1
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
@@ -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
- user = csv.rows # => [#<Row id=1, username="buren">]
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
- Add your own converter
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
- See [`Configuration#default_converters`](https://github.com/buren/honey_format/tree/master/lib/honey_format/configuration.rb#L38) for a complete list of the default ones.
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=[30] Benchmark warmup (default: 30)
420
+ --warmup=[5] Benchmark warmup (default: 5)
407
421
  -h, --help How to use
408
422
  ```
409
423
 
@@ -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] || raise(ArgumentError, 'input path required')
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,
@@ -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
  {
@@ -123,6 +123,7 @@ module HoneyFormat
123
123
  nil: ConvertNil,
124
124
  blank: ConvertBlank,
125
125
  header_column: ConvertHeaderColumn,
126
+ method_name: ConvertHeaderColumn,
126
127
  }.freeze
127
128
  end
128
129
  end
@@ -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
- [/\\/, '/'], # replace "\" with "/"
15
- [/ \(/, '('], # replace " (" with "("
16
- [/ \[/, '['], # replace " [" with "["
17
- [/ \{/, '{'], # replace " {" with "{"
18
- [/ \{/, '{'], # replace " {" with "{"
19
- [/\) /, ')'], # replace ") " with ")"
20
- [/\] /, ']'], # replace "] " with "]"
21
- [/\} /, '}'], # replace "} " with "}"
22
- [BRACKETS, '_'], # replace (, [, {, ), ] and } with "_"
23
- [/ +/, '_'], # replace one or more spaces with "_"
24
- [/-/, '_'], # replace "-" with "_"
25
- [/\.|,/, '_'], # replace "." and "," with "_"
26
- [/::/, '_'], # replace "::" with "_"
27
- [%r{/}, '_'], # replace "/" with "_"
28
- [SEPS, '_'], # replace separator chars with "_"
29
- [/_+/, '_'], # replace one or more "_" with single "_"
30
- [/\A_+/, ''], # remove leading "_"
31
- [/_+\z/, ''], # remove trailing "_"
32
- ].map(&:freeze).freeze
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
 
@@ -15,6 +15,7 @@ module HoneyFormat
15
15
 
16
16
  values = Array.new(value) { |i| i }.map do |index|
17
17
  next key if index.zero?
18
+
18
19
  :"#{key}#{index}"
19
20
  end
20
21
  array.concat(values)
@@ -147,6 +147,7 @@ module HoneyFormat
147
147
  def converter_arity
148
148
  # procs and lambdas respond to #arity
149
149
  return @converter.arity if @converter.respond_to?(:arity)
150
+
150
151
  @converter.method(:call).arity
151
152
  end
152
153
 
@@ -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
 
@@ -78,6 +78,7 @@ module HoneyFormat
78
78
  rows.each do |row|
79
79
  # ignore empty rows
80
80
  next if row.nil? || row.empty? || row == [nil]
81
+
81
82
  built_rows << builder.build(row)
82
83
  end
83
84
  built_rows
@@ -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
 
@@ -4,7 +4,7 @@ module HoneyFormat
4
4
  # Gem version
5
5
  VERSION = [
6
6
  MAJOR_VERSION = 0,
7
- MINOR_VERSION = 18,
7
+ MINOR_VERSION = 19,
8
8
  PATCH_VERSION = 0,
9
9
  ].join('.')
10
10
  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.18.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-07-31 00:00:00.000000000 Z
11
+ date: 2018-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips