table_structure 0.3.10 → 0.3.11
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/Gemfile.lock +1 -1
- data/lib/table_structure/csv/writer.rb +35 -11
- data/lib/table_structure/schema/column/attrs.rb +4 -4
- data/lib/table_structure/schema/table.rb +5 -5
- data/lib/table_structure/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: ccde21d51d86d14d5aba71a9924bcc8d3669032b380005019866699cf5a9fd87
|
4
|
+
data.tar.gz: 31d7f45528e0972886db3a2f07f53cd030671bbabc79dda03e6728262da56d95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '04844310bb6ebc8eb89aa78d9ee4f350ffa566d581d3acd555bdef70271326d674cb2e8dad9843b243a46daea29f0fe0ac879eeaa15da7b68b34c5c93dc670e4'
|
7
|
+
data.tar.gz: aebff92798ac40979500d660e4392eb567bcf4f0efbbc825859fc9a60b5b8be52e458776adab3665243706df995314834512335a7e0aa01f0b526b65d6509f6e
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,27 +5,51 @@ module TableStructure
|
|
5
5
|
class Writer
|
6
6
|
DEFAULT_OPTIONS = {
|
7
7
|
bom: false,
|
8
|
-
|
9
|
-
header_context: nil
|
8
|
+
csv_options: {}
|
10
9
|
}.freeze
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
INNER_WRITER_DEFAULT_OPTIONS = ::TableStructure::Writer::DEFAULT_OPTIONS
|
12
|
+
INNER_WRITER_IGNORED_OPTION_KEYS = %i[
|
13
|
+
result_type
|
14
|
+
method
|
15
|
+
].freeze
|
16
16
|
|
17
17
|
BOM = "\uFEFF"
|
18
18
|
|
19
19
|
def initialize(schema, **options)
|
20
20
|
require 'csv'
|
21
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
22
|
-
|
21
|
+
@options = DEFAULT_OPTIONS.merge(select_csv_writer_options(options))
|
22
|
+
inner_writer_options = select_inner_writer_options(options)
|
23
|
+
@writer = ::TableStructure::Writer.new(schema, **inner_writer_options)
|
23
24
|
end
|
24
25
|
|
25
26
|
def write(items, to:, **options, &block)
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
csv_writer_options = @options.merge(select_csv_writer_options(options))
|
28
|
+
inner_writer_options = select_inner_writer_options(options)
|
29
|
+
if csv_writer_options[:bom]
|
30
|
+
to.send(INNER_WRITER_DEFAULT_OPTIONS[:method], BOM)
|
31
|
+
end
|
32
|
+
csv = ::CSV.new(to, **csv_writer_options[:csv_options])
|
33
|
+
@writer.write(items, to: csv, **inner_writer_options, &block)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def select_csv_writer_options(options)
|
39
|
+
options
|
40
|
+
.select { |k, _v| DEFAULT_OPTIONS.include?(k) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def select_inner_writer_options(options)
|
44
|
+
options
|
45
|
+
.select { |k, _v| INNER_WRITER_DEFAULT_OPTIONS.include?(k) }
|
46
|
+
.reject do |k, v|
|
47
|
+
ignored = INNER_WRITER_IGNORED_OPTION_KEYS.include?(k)
|
48
|
+
if ignored
|
49
|
+
warn "[TableStructure] #{self.class.name} ignores `#{k}:#{v}` option."
|
50
|
+
end
|
51
|
+
ignored
|
52
|
+
end
|
29
53
|
end
|
30
54
|
end
|
31
55
|
end
|
@@ -14,13 +14,13 @@ module TableStructure
|
|
14
14
|
@options = options
|
15
15
|
end
|
16
16
|
|
17
|
-
def name(
|
18
|
-
name = Utils.evaluate_callable(@name,
|
17
|
+
def name(context, table_context)
|
18
|
+
name = Utils.evaluate_callable(@name, context, table_context)
|
19
19
|
optimize_size(name, @size)
|
20
20
|
end
|
21
21
|
|
22
|
-
def value(
|
23
|
-
value = Utils.evaluate_callable(@value,
|
22
|
+
def value(context, table_context)
|
23
|
+
value = Utils.evaluate_callable(@value, context, table_context)
|
24
24
|
optimize_size(value, @size)
|
25
25
|
end
|
26
26
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module TableStructure
|
4
4
|
module Schema
|
5
5
|
class Table
|
6
|
-
# TODO:
|
6
|
+
# TODO: Remove following `attr_reader`.
|
7
7
|
attr_reader :header_column_converters, :row_column_converters, :result_builders
|
8
8
|
|
9
9
|
def initialize(
|
@@ -55,11 +55,11 @@ module TableStructure
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def header(context: nil)
|
58
|
-
values(:name, context
|
58
|
+
values(:name, context)
|
59
59
|
end
|
60
60
|
|
61
61
|
def row(context: nil)
|
62
|
-
values(:value, context
|
62
|
+
values(:value, context)
|
63
63
|
end
|
64
64
|
|
65
65
|
private
|
@@ -75,10 +75,10 @@ module TableStructure
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def size
|
78
|
-
@size ||= @columns.map(&:size).reduce(0
|
78
|
+
@size ||= @columns.map(&:size).reduce(0, &:+)
|
79
79
|
end
|
80
80
|
|
81
|
-
def values(method, context
|
81
|
+
def values(method, context)
|
82
82
|
@columns
|
83
83
|
.map { |column| column.send(method, context, @context) }
|
84
84
|
.flatten
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_structure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jsmmr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|