table_structure 0.4.0 → 0.4.1
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 +9 -1
- data/Gemfile.lock +1 -1
- data/lib/table_structure.rb +0 -1
- data/lib/table_structure/csv/writer.rb +1 -1
- data/lib/table_structure/iterator.rb +37 -20
- data/lib/table_structure/version.rb +1 -1
- data/lib/table_structure/writer.rb +1 -1
- metadata +2 -3
- data/lib/table_structure/table/iterator.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bffa1aa49a812a2f4c1998aac9a297eeabe871a0c49376da090546da3a47a2d
|
4
|
+
data.tar.gz: 8bd2243648e9c2768339813f407e81cf2a94bd5e858349f9de0eaeb52acb6bfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523e57f201c4aad11b038156676fa3c0c8835248366a7bb49929dc580265001f73c4a858049e972a782bf99d7f0a664407a6e258bdf94c616225b633c5d3461c
|
7
|
+
data.tar.gz: e3620fdee15c2bdb77d22224426d31c83349ba469f386681926d58963d5ee986b50b98b527cbc7d23e74edd8fba0891d8db2dd9ec7e256e7421cfdae890bf224
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,15 @@
|
|
1
|
+
# 0.4.1
|
2
|
+
Changes:
|
3
|
+
- `TableStructure::Iterator`
|
4
|
+
- `TableStructure::Writer`
|
5
|
+
- `TableStructure::CSV::Writer`
|
6
|
+
- Add `header: { step: n }` option. Header rows are output at intervals of step number.
|
7
|
+
- e.g. `TableStructure::Iterator.new(schema, header: { step: 10 })`
|
8
|
+
|
1
9
|
# 0.4.0
|
2
10
|
Changes:
|
3
11
|
- Remove deprecated methods, arguments and options.
|
4
|
-
- It is recommended that you update to 0.3.23 first.
|
12
|
+
- It is recommended that you update to `0.3.23` first. If you get warnings or errors, fix them and then update to `0.4.0`.
|
5
13
|
|
6
14
|
# 0.3.23
|
7
15
|
Changes:
|
data/Gemfile.lock
CHANGED
data/lib/table_structure.rb
CHANGED
@@ -30,7 +30,6 @@ module TableStructure
|
|
30
30
|
require 'table_structure/table/column_converter'
|
31
31
|
require 'table_structure/table/context_builder'
|
32
32
|
require 'table_structure/table/row_builder'
|
33
|
-
require 'table_structure/table/iterator'
|
34
33
|
require 'table_structure/writer'
|
35
34
|
require 'table_structure/csv/writer'
|
36
35
|
require 'table_structure/iterator'
|
@@ -2,16 +2,26 @@
|
|
2
2
|
|
3
3
|
module TableStructure
|
4
4
|
class Iterator
|
5
|
+
class HeaderOptions
|
6
|
+
attr_reader :enabled, :context, :step
|
7
|
+
alias enabled? enabled
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@enabled = !!options
|
11
|
+
if options.is_a?(Hash)
|
12
|
+
@context = options[:context]
|
13
|
+
@step = options[:step]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
5
18
|
def initialize(
|
6
19
|
schema,
|
7
|
-
header: { context: nil },
|
20
|
+
header: { context: nil, step: nil },
|
8
21
|
row_type: :array
|
9
22
|
)
|
10
|
-
@
|
11
|
-
@
|
12
|
-
header: header,
|
13
|
-
row_type: row_type
|
14
|
-
}
|
23
|
+
@table = Table.new(schema, row_type: row_type)
|
24
|
+
@header_options = HeaderOptions.new(header)
|
15
25
|
end
|
16
26
|
|
17
27
|
def iterate(items, &block)
|
@@ -19,22 +29,29 @@ module TableStructure
|
|
19
29
|
raise ::TableStructure::Error, "Must be enumerable. #{items}"
|
20
30
|
end
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
header: @
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
table_enum = ::Enumerator.new do |y|
|
33
|
+
body_enum = @table.body(items)
|
34
|
+
|
35
|
+
if @header_options.enabled?
|
36
|
+
header_row = @table.header(context: @header_options.context)
|
37
|
+
y << header_row
|
38
|
+
|
39
|
+
if @header_options.step&.positive?
|
40
|
+
loop do
|
41
|
+
@header_options.step.times { y << body_enum.next }
|
42
|
+
y << header_row
|
43
|
+
end
|
44
|
+
else
|
45
|
+
body_enum.each { |row| y << row }
|
46
|
+
end
|
47
|
+
else
|
48
|
+
body_enum.each { |row| y << row }
|
49
|
+
end
|
35
50
|
end
|
36
51
|
|
37
|
-
|
52
|
+
table_enum = table_enum.lazy.map(&block) if block_given?
|
53
|
+
|
54
|
+
table_enum
|
38
55
|
end
|
39
56
|
end
|
40
57
|
end
|
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.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jsmmr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-04-
|
11
|
+
date: 2020-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,7 +97,6 @@ files:
|
|
97
97
|
- lib/table_structure/table.rb
|
98
98
|
- lib/table_structure/table/column_converter.rb
|
99
99
|
- lib/table_structure/table/context_builder.rb
|
100
|
-
- lib/table_structure/table/iterator.rb
|
101
100
|
- lib/table_structure/table/row_builder.rb
|
102
101
|
- lib/table_structure/version.rb
|
103
102
|
- lib/table_structure/writer.rb
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module TableStructure
|
4
|
-
class Table::Iterator
|
5
|
-
def initialize(table, header: { context: nil })
|
6
|
-
@table = table
|
7
|
-
@header_options = header
|
8
|
-
end
|
9
|
-
|
10
|
-
def iterate(items)
|
11
|
-
::Enumerator.new do |y|
|
12
|
-
if @header_options
|
13
|
-
header_context = @header_options.is_a?(Hash) ? @header_options[:context] : nil
|
14
|
-
y << @table.header(context: header_context)
|
15
|
-
end
|
16
|
-
@table
|
17
|
-
.body(items)
|
18
|
-
.each { |row| y << row }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|