table_structure 0.1.0
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +164 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/table_structure/schema/column.rb +59 -0
- data/lib/table_structure/schema/dsl/column_converter.rb +16 -0
- data/lib/table_structure/schema/dsl/column_definition.rb +20 -0
- data/lib/table_structure/schema/dsl/context_builder.rb +16 -0
- data/lib/table_structure/schema/dsl/result_builder.rb +16 -0
- data/lib/table_structure/schema/table.rb +64 -0
- data/lib/table_structure/schema/utils.rb +9 -0
- data/lib/table_structure/schema.rb +39 -0
- data/lib/table_structure/version.rb +3 -0
- data/lib/table_structure/writer.rb +38 -0
- data/lib/table_structure.rb +15 -0
- data/table_structure.gemspec +29 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d8ca881e2b3849083365015064f38fc94c885548
|
4
|
+
data.tar.gz: 74bdef1d20a72ebcf5fa0d224d40ee05b3b8352f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f1072e0b87a939a86d6c36d01b0583e2ee9573b69f0080da6e6e637f22908500acb1886c940f5da5dcec5c4b513618b0c0fc015fd858eb1bc008df76a1aa18b
|
7
|
+
data.tar.gz: e25cd9540d0cedc13e93dcd7d80162a02975b31d63b0522160e6e07d129ae99ae62b19d5a573cf69afbed73f9ba772adfa3692d0079a1e3b8d4c74b5c4eee505
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
table_structure (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.8.0)
|
12
|
+
rspec-core (~> 3.8.0)
|
13
|
+
rspec-expectations (~> 3.8.0)
|
14
|
+
rspec-mocks (~> 3.8.0)
|
15
|
+
rspec-core (3.8.2)
|
16
|
+
rspec-support (~> 3.8.0)
|
17
|
+
rspec-expectations (3.8.4)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.8.0)
|
20
|
+
rspec-mocks (3.8.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-support (3.8.2)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.17)
|
30
|
+
rake (~> 10.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
table_structure!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
# TableStructure
|
2
|
+
|
3
|
+
`TableStructure` has two major functions.
|
4
|
+
The functions are `TableStructure::Schema` that defines the schema of a table using DSL and ` TableStructure::Writer` that converts and outputs data with that schema.
|
5
|
+
|
6
|
+
`TableStructure::Writer` outputs the converted data line by line.
|
7
|
+
This keeps the memory usage constant and is suitable for large-scale CSV output.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'table_structure'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install table_structure
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
### Basic
|
28
|
+
|
29
|
+
#### TableStructure::Schema
|
30
|
+
```ruby
|
31
|
+
class SampleTableSchema
|
32
|
+
include TableStructure::Schema
|
33
|
+
|
34
|
+
column name: 'ID',
|
35
|
+
value: ->(row, _table) { row[:id] }
|
36
|
+
|
37
|
+
column name: 'Name',
|
38
|
+
value: ->(row, *) { row[:name] }
|
39
|
+
|
40
|
+
columns name: ['Pet 1', 'Pet 2', 'Pet 3'],
|
41
|
+
value: ->(row, *) { row[:pets] }
|
42
|
+
|
43
|
+
columns ->(table) do
|
44
|
+
table[:questions].map do |question|
|
45
|
+
{
|
46
|
+
name: question[:id],
|
47
|
+
value: ->(row, *) { row[:answers][question[:id]] }
|
48
|
+
}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
column_converter :to_s, ->(val, _row, _table) { val.to_s }
|
53
|
+
end
|
54
|
+
|
55
|
+
context = {
|
56
|
+
questions: [
|
57
|
+
{ id: 'Q1', text: 'Do you like sushi?' },
|
58
|
+
{ id: 'Q2', text: 'Do you like yakiniku?' },
|
59
|
+
{ id: 'Q3', text: 'Do you like ramen?' }
|
60
|
+
]
|
61
|
+
}
|
62
|
+
|
63
|
+
schema = SampleTableSchema.new(context: context)
|
64
|
+
```
|
65
|
+
|
66
|
+
#### TableStructure::Writer
|
67
|
+
```ruby
|
68
|
+
writer = TableStructure::Writer.new(schema)
|
69
|
+
|
70
|
+
items = [
|
71
|
+
{
|
72
|
+
id: 1,
|
73
|
+
name: 'Taro',
|
74
|
+
pets: ['🐱', '🐶'],
|
75
|
+
answers: { 'Q1' => '⭕️', 'Q2' => '❌', 'Q3' => '⭕️' }
|
76
|
+
},
|
77
|
+
{
|
78
|
+
id: 2,
|
79
|
+
name: 'Hanako',
|
80
|
+
pets: ['🐇', '🐢', '🐿', '🦒'],
|
81
|
+
answers: { 'Q1' => '⭕️', 'Q2' => '⭕️', 'Q3' => '❌' }
|
82
|
+
}
|
83
|
+
]
|
84
|
+
|
85
|
+
## When using `find_each` method of Rails
|
86
|
+
# items = ->(y) { Records.find_each {|r| y << r } }
|
87
|
+
|
88
|
+
# Output to array
|
89
|
+
table = []
|
90
|
+
writer.write(items, to: table)
|
91
|
+
|
92
|
+
# table
|
93
|
+
# => [["ID", "Name", "Pet 1", "Pet 2", "Pet 3", "Q1", "Q2", "Q3"], ["1", "Taro", "🐱", "🐶", "", "⭕️", "❌", "⭕️"], ["2", "Hanako", "🐇", "🐢", "🐿", "⭕️", "⭕️", "❌"]]
|
94
|
+
|
95
|
+
# Output to file as CSV
|
96
|
+
File.open('sample.csv', 'w') do |f|
|
97
|
+
writer.write(items, to: CSV.new(f))
|
98
|
+
end
|
99
|
+
|
100
|
+
# Output to stream as CSV with Rails
|
101
|
+
response.headers['X-Accel-Buffering'] = 'no' # When using Nginx for reverse proxy
|
102
|
+
response.headers['Cache-Control'] = 'no-cache'
|
103
|
+
response.headers['Content-Type'] = 'text/csv'
|
104
|
+
response.headers['Content-Disposition'] = 'attachment; filename="sample.csv"'
|
105
|
+
response_body = Enumerator.new { |y| writer.write(items, to: CSV.new(y)) }
|
106
|
+
```
|
107
|
+
|
108
|
+
### Advanced
|
109
|
+
|
110
|
+
You can also use `context_builder`.
|
111
|
+
This may be useful when `column` definition lambda is complicated.
|
112
|
+
```ruby
|
113
|
+
class SampleTableSchema
|
114
|
+
include TableStructure::Schema
|
115
|
+
|
116
|
+
TableContext = Struct.new(:questions, keyword_init: true)
|
117
|
+
|
118
|
+
RowContext = Struct.new(:id, :name, :pets, :answers, keyword_init: true) {
|
119
|
+
def more_pets
|
120
|
+
pets + pets
|
121
|
+
end
|
122
|
+
}
|
123
|
+
|
124
|
+
context_builder :table, ->(context) { TableContext.new(**context) }
|
125
|
+
context_builder :row, ->(context) { RowContext.new(**context) }
|
126
|
+
|
127
|
+
column name: 'ID',
|
128
|
+
value: ->(row, _table) { row.id }
|
129
|
+
|
130
|
+
column name: 'Name',
|
131
|
+
value: ->(row, *) { row.name }
|
132
|
+
|
133
|
+
columns name: ['Pet 1', 'Pet 2', 'Pet 3'],
|
134
|
+
value: ->(row, *) { row.more_pets }
|
135
|
+
|
136
|
+
columns ->(table) {
|
137
|
+
table.questions.map do |question|
|
138
|
+
{
|
139
|
+
name: question[:id],
|
140
|
+
value: ->(row, *) { row.answers[question[:id]] }
|
141
|
+
}
|
142
|
+
end
|
143
|
+
}
|
144
|
+
|
145
|
+
column_converter :to_s, ->(val, *) { val.to_s }
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
If you want to convert CSV character code, see the code below.
|
150
|
+
```ruby
|
151
|
+
File.open('sample.csv', 'w') do |f|
|
152
|
+
writer.write(items, to: CSV.new(f)) do |row_values|
|
153
|
+
row_values.map { |val| val&.to_s&.encode('Shift_JIS', invalid: :replace, undef: :replace) }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
158
|
+
## Contributing
|
159
|
+
|
160
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jsmmr/ruby_table_structure.
|
161
|
+
|
162
|
+
## License
|
163
|
+
|
164
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "table_structure"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module TableStructure
|
2
|
+
module Schema
|
3
|
+
class Column
|
4
|
+
def initialize(name: nil, key: nil, value:, size: nil)
|
5
|
+
@name = name
|
6
|
+
@key = key
|
7
|
+
@value = value
|
8
|
+
@size = specify_size(specified_size: size)
|
9
|
+
end
|
10
|
+
|
11
|
+
def name(header_context, table_context)
|
12
|
+
Utils.evaluate_callable(@name, header_context, table_context)
|
13
|
+
end
|
14
|
+
|
15
|
+
def key
|
16
|
+
@key
|
17
|
+
end
|
18
|
+
|
19
|
+
def value(row_context, table_context)
|
20
|
+
val = Utils.evaluate_callable(@value, row_context, table_context)
|
21
|
+
optimize_size(val)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def specify_size(specified_size:)
|
27
|
+
if @name.kind_of?(Array)
|
28
|
+
@name.size
|
29
|
+
elsif @name.respond_to?(:call)
|
30
|
+
unless specified_size
|
31
|
+
raise ::TableStructure::Error.new(
|
32
|
+
":size must be specified when :name is lambda, because columns size is ambiguous."
|
33
|
+
)
|
34
|
+
end
|
35
|
+
specified_size
|
36
|
+
else
|
37
|
+
1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def multiple?
|
42
|
+
@size > 1
|
43
|
+
end
|
44
|
+
|
45
|
+
def optimize_size(value)
|
46
|
+
return value unless multiple?
|
47
|
+
values = value.kind_of?(Array) ? value : [value]
|
48
|
+
actual_size = values.size
|
49
|
+
if actual_size > @size
|
50
|
+
values[0, @size]
|
51
|
+
elsif actual_size < @size
|
52
|
+
[].concat(values).fill(nil, actual_size, (@size - actual_size))
|
53
|
+
else
|
54
|
+
values
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module TableStructure
|
2
|
+
module Schema
|
3
|
+
module DSL
|
4
|
+
module ColumnConverter
|
5
|
+
def column_converter(name, callable)
|
6
|
+
column_converters[name] = callable
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
def column_converters
|
11
|
+
@table_structure_schema_column_converters__ ||= {}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module TableStructure
|
2
|
+
module Schema
|
3
|
+
module DSL
|
4
|
+
module ColumnDefinition
|
5
|
+
def column(definition)
|
6
|
+
column_definitions << definition
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
def columns(definition)
|
11
|
+
column(definition)
|
12
|
+
end
|
13
|
+
|
14
|
+
def column_definitions
|
15
|
+
@table_structure_schema_column_definitions__ ||= []
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module TableStructure
|
2
|
+
module Schema
|
3
|
+
module DSL
|
4
|
+
module ContextBuilder
|
5
|
+
def context_builder(name, callable)
|
6
|
+
context_builders[name] = callable
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
def context_builders
|
11
|
+
@table_structure_schema_context_builders__ ||= Hash.new(->(val) { val })
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module TableStructure
|
2
|
+
module Schema
|
3
|
+
module DSL
|
4
|
+
module ResultBuilder
|
5
|
+
def result_builder(name, callable)
|
6
|
+
result_builders[name] = callable
|
7
|
+
return
|
8
|
+
end
|
9
|
+
|
10
|
+
def result_builders
|
11
|
+
@table_structure_schema_result_builders__ ||= {}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module TableStructure
|
2
|
+
module Schema
|
3
|
+
class Table
|
4
|
+
|
5
|
+
DEFAULT_OPTIONS = { result_type: :array }
|
6
|
+
|
7
|
+
attr_reader :column_converters, :result_builders
|
8
|
+
|
9
|
+
def initialize(column_definitions, column_converters, result_builders, context, options)
|
10
|
+
@context = context
|
11
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
12
|
+
@columns = build_columns(column_definitions)
|
13
|
+
@column_converters = default_column_converters.merge(column_converters)
|
14
|
+
@result_builders = default_result_builders.merge(result_builders)
|
15
|
+
end
|
16
|
+
|
17
|
+
def header(context)
|
18
|
+
values(:name, context)
|
19
|
+
end
|
20
|
+
|
21
|
+
def row(context)
|
22
|
+
values(:value, context)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def build_columns(column_definitions)
|
28
|
+
column_definitions
|
29
|
+
.map { |column| Utils.evaluate_callable(column, @context) }
|
30
|
+
.flatten
|
31
|
+
.map { |column| Column.new(**column) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def default_column_converters
|
35
|
+
{}
|
36
|
+
end
|
37
|
+
|
38
|
+
def default_result_builders
|
39
|
+
result_builders = {}
|
40
|
+
if @options[:result_type] == :hash
|
41
|
+
result_builders[:to_h] = ->(array, *) { (@keys ||= keys).zip(array).to_h }
|
42
|
+
end
|
43
|
+
result_builders
|
44
|
+
end
|
45
|
+
|
46
|
+
def keys
|
47
|
+
@columns.map(&:key).flatten
|
48
|
+
end
|
49
|
+
|
50
|
+
def values(method, context)
|
51
|
+
columns = @columns
|
52
|
+
.map { |column| column.send(method, context, @context) }
|
53
|
+
.flatten
|
54
|
+
.map { |val| reduce_callables(@column_converters, val, context) }
|
55
|
+
reduce_callables(@result_builders, columns, context)
|
56
|
+
end
|
57
|
+
|
58
|
+
def reduce_callables(callables, val, context)
|
59
|
+
callables.reduce(val) { |val, (_, callable)| callable.call(val, context, @context) }
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module TableStructure
|
2
|
+
module Schema
|
3
|
+
def self.included(klass)
|
4
|
+
klass.extend(DSL::ColumnConverter)
|
5
|
+
klass.extend(DSL::ColumnDefinition)
|
6
|
+
klass.extend(DSL::ContextBuilder)
|
7
|
+
klass.extend(DSL::ResultBuilder)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(context: nil, **options)
|
11
|
+
column_definitions = self.class.column_definitions
|
12
|
+
column_converters = self.class.column_converters
|
13
|
+
result_builders = self.class.result_builders
|
14
|
+
context = self.class.context_builders[:table].call(context)
|
15
|
+
@table_structure_schema_table_ =
|
16
|
+
Table.new(
|
17
|
+
column_definitions,
|
18
|
+
column_converters,
|
19
|
+
result_builders,
|
20
|
+
context,
|
21
|
+
options
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
def header(context: nil)
|
26
|
+
context = self.class.context_builders[:header].call(context)
|
27
|
+
@table_structure_schema_table_.header(context)
|
28
|
+
end
|
29
|
+
|
30
|
+
def row(context: nil)
|
31
|
+
context = self.class.context_builders[:row].call(context)
|
32
|
+
@table_structure_schema_table_.row(context)
|
33
|
+
end
|
34
|
+
|
35
|
+
def column_converters
|
36
|
+
@table_structure_schema_table_.column_converters
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module TableStructure
|
2
|
+
class Writer
|
3
|
+
|
4
|
+
DEFAULT_OPTIONS = {
|
5
|
+
header_omitted: false,
|
6
|
+
header_context: nil,
|
7
|
+
method: :<<
|
8
|
+
}
|
9
|
+
|
10
|
+
def initialize(schema, **options)
|
11
|
+
@schema = schema
|
12
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def write(items, to:, **options)
|
16
|
+
options = @options.merge(options)
|
17
|
+
unless options[:header_omitted]
|
18
|
+
header = @schema.header(context: options[:header_context])
|
19
|
+
header = yield header if block_given?
|
20
|
+
to.send(options[:method], header)
|
21
|
+
end
|
22
|
+
to_enum(items).each do |item|
|
23
|
+
row = @schema.row(context: item)
|
24
|
+
row = yield row if block_given?
|
25
|
+
to.send(options[:method], row)
|
26
|
+
end
|
27
|
+
return
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def to_enum(items)
|
33
|
+
items.respond_to?(:call) ?
|
34
|
+
Enumerator.new { |y| items.call(y) } :
|
35
|
+
items
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module TableStructure
|
2
|
+
require 'table_structure/version'
|
3
|
+
|
4
|
+
require 'table_structure/schema'
|
5
|
+
require 'table_structure/schema/dsl/column_converter'
|
6
|
+
require 'table_structure/schema/dsl/column_definition'
|
7
|
+
require 'table_structure/schema/dsl/context_builder'
|
8
|
+
require 'table_structure/schema/dsl/result_builder'
|
9
|
+
require 'table_structure/schema/table'
|
10
|
+
require 'table_structure/schema/column'
|
11
|
+
require 'table_structure/schema/utils'
|
12
|
+
require 'table_structure/writer'
|
13
|
+
|
14
|
+
class Error < StandardError; end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "table_structure/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "table_structure"
|
8
|
+
spec.version = TableStructure::VERSION
|
9
|
+
spec.authors = ["jsmmr"]
|
10
|
+
spec.email = ["jsmmr@icloud.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Create and output table structure data.}
|
13
|
+
spec.description = %q{This gem creates and outputs table structure data. Useful for outputting large CSV file.}
|
14
|
+
spec.homepage = "https://github.com/jsmmr/ruby_table_structure"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: table_structure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jsmmr
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: This gem creates and outputs table structure data. Useful for outputting
|
56
|
+
large CSV file.
|
57
|
+
email:
|
58
|
+
- jsmmr@icloud.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- Gemfile.lock
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- bin/console
|
72
|
+
- bin/setup
|
73
|
+
- lib/table_structure.rb
|
74
|
+
- lib/table_structure/schema.rb
|
75
|
+
- lib/table_structure/schema/column.rb
|
76
|
+
- lib/table_structure/schema/dsl/column_converter.rb
|
77
|
+
- lib/table_structure/schema/dsl/column_definition.rb
|
78
|
+
- lib/table_structure/schema/dsl/context_builder.rb
|
79
|
+
- lib/table_structure/schema/dsl/result_builder.rb
|
80
|
+
- lib/table_structure/schema/table.rb
|
81
|
+
- lib/table_structure/schema/utils.rb
|
82
|
+
- lib/table_structure/version.rb
|
83
|
+
- lib/table_structure/writer.rb
|
84
|
+
- table_structure.gemspec
|
85
|
+
homepage: https://github.com/jsmmr/ruby_table_structure
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.6.14.4
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Create and output table structure data.
|
109
|
+
test_files: []
|