honey_format 0.24.0 → 0.25.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: 4e7b05a5cbde9ef4df67f043ff78e75c545563faa02333c57c97f70f1adec0f9
4
- data.tar.gz: 91275865eabfd283c22ef0507a76b0c433d64a36c2ab68d92501548b982a00c8
3
+ metadata.gz: bba6cf8014cc6cfa59c8519bbb2448d22800e3f5c3699629fd74132f5b615b82
4
+ data.tar.gz: d1e7dc2ed46e061edd4d473a267c5c1a0296fd58f080e7fecd878341364cb90f
5
5
  SHA512:
6
- metadata.gz: c5904b276f295163855c1d74f7afa27568572e50583ec54532e571f70eb59ce06648e60a0e0d29806289d7126b8d0a9351acdd746967c247db03004cec3c4356
7
- data.tar.gz: e498be3c0e31e594cc42d2186404d367564111d70d2fffbe0011d0ea208e5f217ff8416061f12cbdff5137b3075e1f09d857b2dd189d785b865381d02c429d07
6
+ metadata.gz: d67aad924dd6d89a56a2e36b1eb84ae2a30e68f71d717fc11c8be960fbf154b0061311105d814b8458b794c6f0a6f93d078fa91efd9c3f3845afcf87c9abfaa4
7
+ data.tar.gz: 2981c007e997cad9e8c58e9cdb4b22654b8f0443ef82345355919068b1bd804d278780808ba361f9077cf1e03bad649060b4474fba99de02a999bc9aea3e7efc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # HEAD
2
2
 
3
+ ## v0.25.0
4
+
5
+ * Add support for adding multiple `Rows` together, `Rows#+`
6
+
3
7
  ## v0.24.0
4
8
 
5
9
  * Add support for multiple/chained converters. [PR#69](https://github.com/buren/honey_format/pull/69)
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018 Jacob Burenstam Linder
3
+ Copyright (c) 2021 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
@@ -323,6 +323,13 @@ user.public_send(:"first^name") # => "Jacob"
323
323
  user['first^name'] # => "Jacob"
324
324
  ```
325
325
 
326
+ Emoji characters
327
+ ```ruby
328
+ csv_string = "😎⛷\nEmoji characters"
329
+ csv = HoneyFormat::CSV.new(csv_string)
330
+ csv.rows.first.😎⛷ # => Emoji characters
331
+ ```
332
+
326
333
  __Errors__
327
334
 
328
335
  > When you need to be extra safe.
@@ -428,6 +435,30 @@ user.name # => buren
428
435
  user.created_at.class # => Time
429
436
  ```
430
437
 
438
+ ## Configuration
439
+
440
+ Configuration is optional
441
+ ```ruby
442
+ HoneyFormat.configure do |config|
443
+ config.header_converter = proc { |column| column.downcase }
444
+ config.delimiter = ";"
445
+ config.row_delimiter = "|"
446
+ config.quote_character = "'"
447
+ config.skip_lines = %r{\A#} # Match all lines that start with "#"
448
+ end
449
+ ```
450
+
451
+ Default configuration values
452
+ ```ruby
453
+ HoneyFormat.configure do |config|
454
+ config.header_converter = HoneyFormat::Registry.new(Converters::DEFAULT)[:header_column]
455
+ config.delimiter = ","
456
+ config.row_delimiter = :auto
457
+ config.quote_character = "\""
458
+ config.skip_lines = nil
459
+ end
460
+ ```
461
+
431
462
  ## CLI
432
463
 
433
464
  > Perfect when you want to get something simple done quickly.
@@ -12,13 +12,18 @@ module HoneyFormat
12
12
  # @param [Array] rows the array of rows.
13
13
  # @param [Array<Symbol>] columns the array of column symbols.
14
14
  # @param type_map [Hash] map of column_name => type conversion to perform.
15
+ # @param pre_built_rows [boolean] whether the rows come pre-built
15
16
  # @raise [RowError] super class of errors raised when there is a row error.
16
17
  # @raise [EmptyRowColumnsError] raised when there are no columns.
17
18
  # @raise [InvalidRowLengthError] raised when row has more columns than header columns.
18
- def initialize(rows, columns, builder: nil, type_map: {})
19
+ def initialize(rows, columns, builder: nil, type_map: {}, pre_built_rows: false)
19
20
  @columns = columns
20
- builder = RowBuilder.new(@columns, builder: builder, type_map: type_map)
21
- @rows = prepare_rows(builder, rows)
21
+ if pre_built_rows
22
+ @rows = rows
23
+ else
24
+ builder = RowBuilder.new(@columns, builder: builder, type_map: type_map)
25
+ @rows = prepare_rows(builder, rows)
26
+ end
22
27
  end
23
28
 
24
29
  # Row columns
@@ -33,6 +38,18 @@ module HoneyFormat
33
38
  @rows.empty?
34
39
  end
35
40
 
41
+ # Returns the rows added together.
42
+ # @return [Rows] the two sets of Rows added together.
43
+ # @param [Rows] the other Rows object.
44
+ def +(other)
45
+ if columns != columns.union(other.columns)
46
+ raise ArgumentError, "can't added two sets of rows with different columns"
47
+ end
48
+
49
+ rows = @rows + other.rows_data
50
+ self.class.new(rows, columns, pre_built_rows: true)
51
+ end
52
+
36
53
  # @yield [row] The given block will be passed for every row.
37
54
  # @yieldparam [Row] a row in the CSV file.
38
55
  # @return [Enumerator]
@@ -49,6 +66,7 @@ module HoneyFormat
49
66
 
50
67
  # Return element at given position.
51
68
  # @return [Row] of rows.
69
+ # @param [Integer] the index to return.
52
70
  def [](index)
53
71
  @rows[index]
54
72
  end
@@ -84,6 +102,12 @@ module HoneyFormat
84
102
  csv_rows.join
85
103
  end
86
104
 
105
+ protected
106
+
107
+ def rows_data
108
+ @rows
109
+ end
110
+
87
111
  private
88
112
 
89
113
  def prepare_rows(builder, rows)
@@ -4,7 +4,7 @@ module HoneyFormat
4
4
  # Gem version
5
5
  VERSION = [
6
6
  MAJOR_VERSION = 0,
7
- MINOR_VERSION = 24,
7
+ MINOR_VERSION = 25,
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.24.0
4
+ version: 0.25.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: 2021-07-06 00:00:00.000000000 Z
11
+ date: 2021-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark-ips