table_transformer 0.0.2 → 0.0.3
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/Gemfile +1 -2
- data/lib/table_transformer/helper.rb +9 -0
- data/lib/table_transformer/line_generator.rb +4 -1
- data/lib/table_transformer/version.rb +1 -1
- data/lib/table_transformer.rb +5 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02e41ec6d95e1584f4e7f08668ac944c3f03a33a
|
4
|
+
data.tar.gz: 769e1d271ba7fcca1d7337168fa907c182ba89a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73870bbb146ae09cdd184937f6088a49df58b60b1bc91b51c147065c4beef2b1ec10d8741a0a975941c44c931f9f4e54afa81f2b7f1ea2a6d724c48971eaf646
|
7
|
+
data.tar.gz: d52fae0f8805c6538ece36d65885a0daf65cb2406b600423ed33fd66838ed4b5c5abdf00d69601b93f72c4763363190f62cff4fca9c98fece1e68d3379692591
|
data/Gemfile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
require "table_transformer/helper"
|
2
|
+
|
1
3
|
module TableTransformer
|
2
4
|
class LineGenerator
|
5
|
+
include Helper
|
3
6
|
attr_reader :column_width
|
4
7
|
def initialize(column_width:)
|
5
8
|
@column_width = column_width
|
@@ -36,7 +39,7 @@ module TableTransformer
|
|
36
39
|
def generate_line(data)
|
37
40
|
"|".tap do |line|
|
38
41
|
column_width.each do |k, v|
|
39
|
-
blank_number = v - data[k]
|
42
|
+
blank_number = v - width(data[k]) - 1
|
40
43
|
line += " " + data[k].to_s + " " * blank_number + "|"
|
41
44
|
end
|
42
45
|
break line
|
data/lib/table_transformer.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require "active_support"
|
2
2
|
require "active_support/core_ext"
|
3
3
|
require "table_transformer/line_generator"
|
4
|
+
require "table_transformer/helper"
|
4
5
|
|
5
6
|
module TableTransformer
|
6
7
|
class Data
|
8
|
+
include Helper
|
7
9
|
attr_reader :original, :keys
|
8
10
|
def initialize(original:, keys: [])
|
9
11
|
@original = if original.class.method_defined?(:keys)
|
@@ -67,7 +69,7 @@ module TableTransformer
|
|
67
69
|
def column_width
|
68
70
|
@column_width ||= {}.tap do |width|
|
69
71
|
keys.each do |k|
|
70
|
-
width[k] = max_size[k] < k
|
72
|
+
width[k] = max_size[k] < width(k) ? width(k) : max_size[k]
|
71
73
|
width[k] += 2
|
72
74
|
end
|
73
75
|
break width
|
@@ -77,8 +79,8 @@ module TableTransformer
|
|
77
79
|
def max_size
|
78
80
|
@max_size ||= {}.tap do |size|
|
79
81
|
keys.each do |k|
|
80
|
-
max_data = string_data.max_by { |data| data[k]
|
81
|
-
size[k] = max_data[k]
|
82
|
+
max_data = string_data.max_by { |data| width(data[k]) }
|
83
|
+
size[k] = width(max_data[k])
|
82
84
|
end
|
83
85
|
break size
|
84
86
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_transformer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akito Ueno
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- bin/console
|
71
71
|
- bin/setup
|
72
72
|
- lib/table_transformer.rb
|
73
|
+
- lib/table_transformer/helper.rb
|
73
74
|
- lib/table_transformer/line_generator.rb
|
74
75
|
- lib/table_transformer/version.rb
|
75
76
|
- table_transformer.gemspec
|