table_structure 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/table_structure.rb +1 -0
- data/lib/table_structure/iterator.rb +3 -4
- data/lib/table_structure/schema.rb +8 -0
- data/lib/table_structure/schema/dsl/option.rb +18 -0
- data/lib/table_structure/schema/table.rb +0 -3
- data/lib/table_structure/version.rb +1 -1
- data/table_structure.gemspec +2 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a8c1be2513b60a1831419aa48faf9c5f326c7dc15ede46343cd9d57cac2caf3
|
4
|
+
data.tar.gz: 5dfbfbbd2589b94e7fc438422bf6b5b7f49bc9b80b594c8da4a6cccd4c13cb7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19dedd18f47cc61c9e9625f23c44cd4423f59423fdfd9906ef694241c08aa182afccd5b93c8be3b13f06ab9abd46465f2c7e959581f72dc52025ebfe1549f611
|
7
|
+
data.tar.gz: f68ac3210c804de84865e02c80e3aac5831284419e5518c28f2f31197e057eaf3da00aae21c96858b8640b391615961de4500411ae4bf4c39780c4ec6410dd46
|
data/Gemfile.lock
CHANGED
data/lib/table_structure.rb
CHANGED
@@ -9,6 +9,7 @@ module TableStructure
|
|
9
9
|
require 'table_structure/schema/dsl/column_converter'
|
10
10
|
require 'table_structure/schema/dsl/column_definition'
|
11
11
|
require 'table_structure/schema/dsl/context_builder'
|
12
|
+
require 'table_structure/schema/dsl/option'
|
12
13
|
require 'table_structure/schema/dsl/result_builder'
|
13
14
|
require 'table_structure/schema/definition'
|
14
15
|
require 'table_structure/schema/definition/error'
|
@@ -3,14 +3,13 @@
|
|
3
3
|
module TableStructure
|
4
4
|
class Iterator
|
5
5
|
def initialize(schema_or_writer, **options)
|
6
|
-
|
7
|
-
when schema_or_writer.is_a?(Schema)
|
6
|
+
if schema_or_writer.is_a?(Schema)
|
8
7
|
schema = schema_or_writer
|
9
8
|
@writer = Writer.new(schema, options)
|
10
|
-
|
9
|
+
elsif schema_or_writer.is_a?(Writer)
|
11
10
|
@writer = schema_or_writer
|
12
11
|
else
|
13
|
-
raise ::TableStructure::Error
|
12
|
+
raise ::TableStructure::Error, 'First argument must be either Schema or Writer.'
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
@@ -6,14 +6,18 @@ module TableStructure
|
|
6
6
|
klass.extend(DSL::ColumnConverter)
|
7
7
|
klass.extend(DSL::ColumnDefinition)
|
8
8
|
klass.extend(DSL::ContextBuilder)
|
9
|
+
klass.extend(DSL::Option)
|
9
10
|
klass.extend(DSL::ResultBuilder)
|
10
11
|
end
|
11
12
|
|
13
|
+
DEFAULT_OPTIONS = { result_type: :array }.freeze
|
14
|
+
|
12
15
|
def initialize(context: nil, **options)
|
13
16
|
column_definitions = self.class.column_definitions
|
14
17
|
column_converters = self.class.column_converters
|
15
18
|
result_builders = self.class.result_builders
|
16
19
|
context = self.class.context_builders[:table].call(context)
|
20
|
+
options = DEFAULT_OPTIONS.merge(self.class.options).merge(options)
|
17
21
|
@table_structure_schema_table_ =
|
18
22
|
Table.new(
|
19
23
|
column_definitions,
|
@@ -37,5 +41,9 @@ module TableStructure
|
|
37
41
|
def column_converters
|
38
42
|
@table_structure_schema_table_.column_converters
|
39
43
|
end
|
44
|
+
|
45
|
+
def result_builders
|
46
|
+
@table_structure_schema_table_.result_builders
|
47
|
+
end
|
40
48
|
end
|
41
49
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module TableStructure
|
4
|
+
module Schema
|
5
|
+
module DSL
|
6
|
+
module Option
|
7
|
+
def option(name, value)
|
8
|
+
options[name] = value
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def options
|
13
|
+
@table_structure_schema_options__ ||= {}
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -3,12 +3,9 @@
|
|
3
3
|
module TableStructure
|
4
4
|
module Schema
|
5
5
|
class Table
|
6
|
-
DEFAULT_OPTIONS = { result_type: :array }.freeze
|
7
|
-
|
8
6
|
attr_reader :columns, :column_converters, :result_builders
|
9
7
|
|
10
8
|
def initialize(column_definitions, column_converters, result_builders, context, options)
|
11
|
-
options = DEFAULT_OPTIONS.merge(options)
|
12
9
|
@columns = build_columns(column_definitions, context, options)
|
13
10
|
@column_converters = default_column_converters.merge(column_converters)
|
14
11
|
@result_builders = default_result_builders(options).merge(result_builders)
|
data/table_structure.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ['jsmmr']
|
11
11
|
spec.email = ['jsmmr@icloud.com']
|
12
12
|
|
13
|
-
spec.summary = 'Create and output table
|
14
|
-
spec.description = 'This gem creates and outputs table
|
13
|
+
spec.summary = 'Create and output table structured data.'
|
14
|
+
spec.description = 'This gem creates and outputs table structured data. Useful for creating CSV.'
|
15
15
|
spec.homepage = 'https://github.com/jsmmr/ruby_table_structure'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jsmmr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description: This gem creates and outputs table
|
55
|
+
description: This gem creates and outputs table structured data. Useful for creating
|
56
56
|
CSV.
|
57
57
|
email:
|
58
58
|
- jsmmr@icloud.com
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/table_structure/schema/dsl/column_converter.rb
|
81
81
|
- lib/table_structure/schema/dsl/column_definition.rb
|
82
82
|
- lib/table_structure/schema/dsl/context_builder.rb
|
83
|
+
- lib/table_structure/schema/dsl/option.rb
|
83
84
|
- lib/table_structure/schema/dsl/result_builder.rb
|
84
85
|
- lib/table_structure/schema/table.rb
|
85
86
|
- lib/table_structure/schema/utils.rb
|
@@ -109,5 +110,5 @@ rubyforge_project:
|
|
109
110
|
rubygems_version: 2.7.6.2
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
|
-
summary: Create and output table
|
113
|
+
summary: Create and output table structured data.
|
113
114
|
test_files: []
|