Skip to content

Commit

Permalink
Use Unicode.width for get value length instead of Stging#length
Browse files Browse the repository at this point in the history
  • Loading branch information
sawanoboly committed Apr 10, 2015
1 parent bf9a343 commit 772a713
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions formatador.gemspec
Expand Up @@ -50,6 +50,7 @@ Gem::Specification.new do |s|
## List your runtime dependencies here. Runtime dependencies are those
## that are needed for an end user to actually USE your code.
# s.add_dependency('DEPNAME', [">= 1.1.0", "< 2.0.0"])
s.add_dependency('unicode')

## List your development dependencies here. Development dependencies are
## those that are only needed during development
Expand Down
1 change: 1 addition & 0 deletions lib/formatador.rb
@@ -1,5 +1,6 @@
require File.join(File.dirname(__FILE__), 'formatador', 'table')
require File.join(File.dirname(__FILE__), 'formatador', 'progressbar')
require 'unicode'

class Formatador

Expand Down
2 changes: 1 addition & 1 deletion lib/formatador/table.rb
Expand Up @@ -80,7 +80,7 @@ def display_compact_table(hashes, keys = nil, &block)
private

def length(value)
value.to_s.gsub(PARSE_REGEX, '').length
Unicode.width(value.to_s.gsub(PARSE_REGEX, ''))
end

def calculate_datum(header, hash)
Expand Down
21 changes: 20 additions & 1 deletion tests/table_tests.rb
@@ -1,3 +1,4 @@
# coding: utf-8
Shindo.tests("Formatador: tables") do

output = <<-OUTPUT
Expand Down Expand Up @@ -93,4 +94,22 @@
end
end

end

output = <<-OUTPUT
+------+
| [bold]a[/] |
+------+
| 1 |
+------+
| 震度 |
+------+
OUTPUT
output = Formatador.parse(output)

tests("#display_table([{:a => 1}, {:a => 2}])").returns(output) do
capture_stdout do
Formatador.display_table([{:a => 1}, {:a => "震度"}])
end
end

end

0 comments on commit 772a713

Please sign in to comment.