table_structure 0.3.18 → 0.3.19

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: b76264ce64e9ba5706af0a933cda2a9bbd64d7c4f49a88ac8cf57c2c96a87d7e
4
- data.tar.gz: e78fa085177724b1fc7a6a5561455588611159226d170840fb4a8ac908feb7aa
3
+ metadata.gz: dd4c31d4dca33325702612875d61ba8c011ffa01bc63ae34a37ef3dc5b288350
4
+ data.tar.gz: 126975799c4d8e7fc2e534c649e43946fb640395b9b040db5d347b2e3562bd48
5
5
  SHA512:
6
- metadata.gz: a767059b75a19a19ad4eff6fb16134ac4cc345bb5dd0878f7d434db274e9ae37c0a708b73e52611eea83deb0e78edd1ed891bcccef666674726c67f43bec699c
7
- data.tar.gz: 94c598813253ca9ae1d20d5853567cfb3d45ef4bb161c69b879988f144265449291b3a3130ca894c8a0aac2545eb13e77e1433ba48fa539cc6541d3cddaa7804
6
+ metadata.gz: 857750dbc07833cc0c137b3041c97ecb5cd1421d0e539f153f614a66c10f8cbe9c7d567c6d73a6982e4c62f9c303f33dcfa28ef850e7aa2941086b9f97371385
7
+ data.tar.gz: 2663d270d999ed8598b9e83d89894517c39e880e2deda23021c7ae9ac83cb24202a18d9970919eb2ad1913ab0889dff9ddd7b997d75f36d1d2293f748afa05c2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 0.3.19
2
+ Changes:
3
+ - `TableStructure::Writer`
4
+ - `header_omitted: true` option has been deprecated. Use `header: false` option instead.
5
+ - `TableStructure::CSV::Writer`
6
+ - `header_omitted: true` option has been deprecated. Use `header: false` option instead.
7
+ - `TableStructure::Iterator`
8
+ - `header_omitted: true` option has been deprecated. Use `header: false` option instead.
9
+
1
10
  # 0.3.18
2
11
  Changes:
3
12
  - Minor improvements.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- table_structure (0.3.18)
4
+ table_structure (0.3.19)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -77,10 +77,10 @@ Initialize a writer with the schema:
77
77
  ```ruby
78
78
  writer = TableStructure::Writer.new(schema)
79
79
  ## To omit header, write:
80
- # writer = TableStructure::Writer.new(schema, header_omitted: true)
80
+ # writer = TableStructure::Writer.new(schema, header: false)
81
81
  ```
82
82
 
83
- Writes the items converted by the schema to array:
83
+ Write the items converted by the schema to array:
84
84
  ```ruby
85
85
  items = [
86
86
  {
@@ -109,14 +109,14 @@ writer.write(items, to: table)
109
109
  # => [["ID", "Name", "Pet 1", "Pet 2", "Pet 3", "Q1", "Q2", "Q3"], ["1", "Taro", "🐱", "🐶", "", "⭕️", "❌", "⭕️"], ["2", "Hanako", "🐇", "🐢", "🐿", "⭕️", "⭕️", "❌"]]
110
110
  ```
111
111
 
112
- Writes the items converted by the schema to file as CSV:
112
+ Write the items converted by the schema to file as CSV:
113
113
  ```ruby
114
114
  File.open('sample.csv', 'w') do |f|
115
115
  writer.write(items, to: CSV.new(f))
116
116
  end
117
117
  ```
118
118
 
119
- Writes the items converted by the schema to stream as CSV with Rails:
119
+ Write the items converted by the schema to stream as CSV with Rails:
120
120
  ```ruby
121
121
  # response.headers['X-Accel-Buffering'] = 'no' # Required if Nginx is used for reverse proxy
122
122
  response.headers['Cache-Control'] = 'no-cache'
@@ -191,7 +191,7 @@ context = {
191
191
  }
192
192
 
193
193
  schema = SampleTableSchema.new(context: context)
194
- iterator = TableStructure::Iterator.new(schema, row_type: :hash, header_omitted: true)
194
+ iterator = TableStructure::Iterator.new(schema, row_type: :hash, header: false)
195
195
  ```
196
196
 
197
197
  Enumerate the items converted by the schema:
@@ -446,12 +446,12 @@ end
446
446
 
447
447
  You can also use only `TableStructure::Schema` instance.
448
448
  ```erb
449
- <% @schema.create_table(row_type: :array) do |table| %>
449
+ <% @schema.create_table(row_type: :hash) do |table| %>
450
450
  <table>
451
451
  <thead>
452
452
  <tr>
453
- <% table.header.each do |val| %>
454
- <th><%= val %></th>
453
+ <% table.header.each do |key, value| %>
454
+ <th class="<%= key %>"><%= value %></th>
455
455
  <% end %>
456
456
  </tr>
457
457
  </thead>
@@ -459,8 +459,8 @@ You can also use only `TableStructure::Schema` instance.
459
459
  <tbody>
460
460
  <% table.body(@items).each do |row| %>
461
461
  <tr>
462
- <% row.each do |val| %>
463
- <td><%= val %></td>
462
+ <% row.each do |key, value| %>
463
+ <td class="<%= key %>"><%= value %></td>
464
464
  <% end %>
465
465
  </tr>
466
466
  <% end %>
@@ -9,9 +9,21 @@ module TableStructure
9
9
  schema,
10
10
  bom: false,
11
11
  csv_options: {},
12
- header_omitted: false,
13
- header_context: nil
12
+ header: { context: nil },
13
+ **deprecated_options
14
14
  )
15
+ if deprecated_options.key?(:header_omitted)
16
+ header_omitted = deprecated_options[:header_omitted]
17
+ warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
18
+ header = !header_omitted
19
+ end
20
+
21
+ if deprecated_options.key?(:header_context)
22
+ header_context = deprecated_options[:header_context]
23
+ warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
24
+ header = { context: header_context }
25
+ end
26
+
15
27
  require 'csv'
16
28
 
17
29
  @options = {
@@ -19,8 +31,7 @@ module TableStructure
19
31
  csv_options: csv_options
20
32
  }
21
33
  @inner_options = {
22
- header_omitted: header_omitted,
23
- header_context: header_context
34
+ header: header
24
35
  }
25
36
 
26
37
  @writer = ::TableStructure::Writer.new(schema, **@inner_options)
@@ -31,13 +42,30 @@ module TableStructure
31
42
  to:,
32
43
  bom: @options[:bom],
33
44
  csv_options: @options[:csv_options],
34
- header_omitted: @inner_options[:header_omitted],
35
- header_context: @inner_options[:header_context],
45
+ **deprecated_options,
36
46
  &block
37
47
  )
48
+ header = @inner_options[:header]
49
+
50
+ if deprecated_options.key?(:header)
51
+ header = deprecated_options[:header]
52
+ warn '[TableStructure] Specify :header option as an argument for initialize method.'
53
+ end
54
+
55
+ if deprecated_options.key?(:header_omitted)
56
+ header_omitted = deprecated_options[:header_omitted]
57
+ warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
58
+ header = !header_omitted
59
+ end
60
+
61
+ if deprecated_options.key?(:header_context)
62
+ header_context = deprecated_options[:header_context]
63
+ warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
64
+ header = { context: header_context }
65
+ end
66
+
38
67
  inner_options = {
39
- header_omitted: header_omitted,
40
- header_context: header_context
68
+ header: header
41
69
  }
42
70
 
43
71
  to << BOM if bom
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableStructure
4
- VERSION = '0.3.18'
4
+ VERSION = '0.3.19'
5
5
  end
@@ -4,12 +4,23 @@ module TableStructure
4
4
  class Writer
5
5
  def initialize(
6
6
  schema,
7
- header_omitted: false,
8
- header_context: nil,
7
+ header: { context: nil },
9
8
  method: :<<,
10
9
  row_type: :array,
11
10
  **deprecated_options
12
11
  )
12
+ if deprecated_options.key?(:header_omitted)
13
+ header_omitted = deprecated_options[:header_omitted]
14
+ warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
15
+ header = !header_omitted
16
+ end
17
+
18
+ if deprecated_options.key?(:header_context)
19
+ header_context = deprecated_options[:header_context]
20
+ warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
21
+ header = { context: header_context }
22
+ end
23
+
13
24
  if deprecated_options.key?(:result_type)
14
25
  warn '[TableStructure] `:result_type` option has been deprecated. Use `:row_type` option instead.'
15
26
  row_type = deprecated_options[:result_type]
@@ -17,8 +28,7 @@ module TableStructure
17
28
 
18
29
  @schema = schema
19
30
  @options = {
20
- header_omitted: header_omitted,
21
- header_context: header_context,
31
+ header: header,
22
32
  method: method,
23
33
  row_type: row_type
24
34
  }
@@ -28,12 +38,34 @@ module TableStructure
28
38
  items,
29
39
  to:,
30
40
  method: @options[:method],
31
- header_omitted: @options[:header_omitted],
32
- header_context: @options[:header_context],
33
- row_type: @options[:row_type],
34
41
  **deprecated_options,
35
42
  &block
36
43
  )
44
+ header = @options[:header]
45
+ row_type = @options[:row_type]
46
+
47
+ if deprecated_options.key?(:header)
48
+ header = deprecated_options[:header]
49
+ warn '[TableStructure] Specify :header option as an argument for initialize method.'
50
+ end
51
+
52
+ if deprecated_options.key?(:header_omitted)
53
+ header_omitted = deprecated_options[:header_omitted]
54
+ warn "[TableStructure] `header_omitted: #{!!header_omitted}` option has been deprecated. Use `header: #{!header_omitted}` option instead."
55
+ header = !header_omitted
56
+ end
57
+
58
+ if deprecated_options.key?(:header_context)
59
+ header_context = deprecated_options[:header_context]
60
+ warn '[TableStructure] `:header_context` option has been deprecated. Use `header: { context: ... }` option instead.'
61
+ header = { context: header_context }
62
+ end
63
+
64
+ if deprecated_options.key?(:row_type)
65
+ row_type = deprecated_options[:row_type]
66
+ warn '[TableStructure] Specify :row_type option as an argument for initialize method.'
67
+ end
68
+
37
69
  if deprecated_options.key?(:result_type)
38
70
  warn '[TableStructure] `:result_type` option has been deprecated. Use `:row_type` option instead.'
39
71
  row_type = deprecated_options[:result_type]
@@ -41,13 +73,6 @@ module TableStructure
41
73
 
42
74
  items = enumerize(items)
43
75
 
44
- header_options =
45
- if header_omitted
46
- false
47
- else
48
- { context: header_context }
49
- end
50
-
51
76
  @schema.create_table(row_type: row_type) do |table|
52
77
  output = Output.new(to, method: method)
53
78
 
@@ -55,7 +80,7 @@ module TableStructure
55
80
  Table::Iterator
56
81
  .new(
57
82
  table,
58
- header: header_options
83
+ header: header
59
84
  )
60
85
  .iterate(items)
61
86
 
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.18
4
+ version: 0.3.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - jsmmr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-15 00:00:00.000000000 Z
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler