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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3749b63b879abaf5369c7c9c20715358a01ad17a
4
- data.tar.gz: 52bc19a464d192c4684cbe71f37aa00bda0df57a
3
+ metadata.gz: 02e41ec6d95e1584f4e7f08668ac944c3f03a33a
4
+ data.tar.gz: 769e1d271ba7fcca1d7337168fa907c182ba89a2
5
5
  SHA512:
6
- metadata.gz: c66fe0d82857433e9e868d145b2997252188bf3a67d11446853c0412a934498b72f3ba0201bccb8d1b3eca95254981589ecc63bd72b203474a9b3ca7aa16a5f1
7
- data.tar.gz: 4c871948618d65ad741ca3443cc6526c9b70051f0467c5060d190937dfd6f7fa546108cdae32aadc6b2e973cce6b82bbb4d7cec192b53237629ea8892573e018
6
+ metadata.gz: 73870bbb146ae09cdd184937f6088a49df58b60b1bc91b51c147065c4beef2b1ec10d8741a0a975941c44c931f9f4e54afa81f2b7f1ea2a6d724c48971eaf646
7
+ data.tar.gz: d52fae0f8805c6538ece36d65885a0daf65cb2406b600423ed33fd66838ed4b5c5abdf00d69601b93f72c4763363190f62cff4fca9c98fece1e68d3379692591
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in table_transformer.gemspec
4
3
  gemspec
5
-
6
4
  gem "activesupport"
5
+ gem "unicode-display_width"
@@ -0,0 +1,9 @@
1
+ require "unicode/display_width"
2
+
3
+ module TableTransformer
4
+ module Helper
5
+ def width(str)
6
+ Unicode::DisplayWidth.of(str.to_s)
7
+ end
8
+ end
9
+ end
@@ -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].size - 1
42
+ blank_number = v - width(data[k]) - 1
40
43
  line += " " + data[k].to_s + " " * blank_number + "|"
41
44
  end
42
45
  break line
@@ -1,3 +1,3 @@
1
1
  module TableTransformer
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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.size ? k.size : max_size[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].to_s.size }
81
- size[k] = max_data[k].to_s.size
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.2
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