honey_format 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/honey_format/row.rb +15 -8
- 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: 3f11a451917cde22eb1749f01e42e12d4bfc3314f0dd42692f27100c452557ab
|
4
|
+
data.tar.gz: 4ad3a5e3be4a82e26fb3715c50011b5f7cc26069ac74058763cc4d097d1f7f0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63090f5e515480669c3dc2a74882e4fc4aba303eb7f2f0e71fbeb67a7f9ccf9f5b0cf592a07af8890e79da2f682ce9f6622be672a141219e1471d559f1ac9223
|
7
|
+
data.tar.gz: 9439ebcfc40892fb57ac3cdca5f74f6c2ac58e0972b5200a6678194376c5063b4cc1083fde94f68c42c302fd720124c6ff3878cbd6b5d5546e92d38c0d4fcc87
|
data/lib/honey_format/row.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
module HoneyFormat
|
2
2
|
# Holds data for a single row.
|
3
3
|
class Row
|
4
|
+
class RowBuilder < Struct
|
5
|
+
def self.call(row)
|
6
|
+
new(*row)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
# Returns a new instance of Row.
|
5
11
|
# @return [Row] a new instance of Row.
|
6
12
|
# @param [Array] columns an array of symbols.
|
@@ -9,9 +15,9 @@ module HoneyFormat
|
|
9
15
|
# Row.new!([:id])
|
10
16
|
def initialize(columns, builder: nil)
|
11
17
|
validate_columns!(columns)
|
12
|
-
@
|
18
|
+
@row_builder = RowBuilder.new(*columns)
|
19
|
+
@builder = builder || ->(row) { row }
|
13
20
|
@columns = columns
|
14
|
-
@builder = builder
|
15
21
|
end
|
16
22
|
|
17
23
|
# Returns a Struct.
|
@@ -19,10 +25,11 @@ module HoneyFormat
|
|
19
25
|
# @param row [Array] the row array.
|
20
26
|
# @raise [InvalidRowLengthError] raised when there are more row elements longer than columns
|
21
27
|
# @example Build new row
|
22
|
-
# r = Row.new
|
28
|
+
# r = Row.new([:id])
|
23
29
|
# r.build(['1']).id #=> '1'
|
24
30
|
def build(row)
|
25
|
-
|
31
|
+
built_row = @row_builder.call(row)
|
32
|
+
@builder.call(built_row)
|
26
33
|
rescue ArgumentError, 'struct size differs'
|
27
34
|
fail_for_struct_size_diff!(row)
|
28
35
|
end
|
@@ -30,10 +37,10 @@ module HoneyFormat
|
|
30
37
|
private
|
31
38
|
|
32
39
|
def validate_columns!(columns)
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
return unless columns.empty?
|
41
|
+
|
42
|
+
err_msg = 'Expected array with at least one element, but was empty.'
|
43
|
+
fail(EmptyColumnsError, err_msg)
|
37
44
|
end
|
38
45
|
|
39
46
|
def fail_for_struct_size_diff!(row)
|
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.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Burenstam
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|