ttable 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0593100cc29009bbec61da7f47c925cf1c5f1043
4
- data.tar.gz: 5d20aca2ee528e308a96ac0f27584f5cd5e8e848
3
+ metadata.gz: 1143d0826e56fc391aab77df86ae4bb65d60e4b7
4
+ data.tar.gz: d9dd441bc44c6acbd8ebc16627b18fab37a05c4f
5
5
  SHA512:
6
- metadata.gz: ef944c97c37bd45bbef0831fad22652e9c3d8127f6a00a394a0ec8c5f265196b7efb79408826abde3217a37019f32901c968defeee96ae3f07f1e0d4d809b1b0
7
- data.tar.gz: 88eefbdc9c9ba2fbc2bccac1691d965d4ae78262279af3c56ac70a6e7d109e91b9f472fb411a9168a6a28601c5c87c59451e772d7d6dde84ad8d79e2030dc47c
6
+ metadata.gz: f6c57c1f6bcd67303b255c6a1ae59b979ce0f4526f5af3245ef267242ead715be3249a55d6ebf97d201f03728b26cf0d97e686a3238975770e575beac18f82b2
7
+ data.tar.gz: dd5306f3053de63bf39403b8eabde5f3f97ca143ce8327ce289bebbf4ed55cd35482489f37e2d45fb9e08a5601290092d884b63a202daf1d433d109107439e32
data/Guardfile CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  guard 'rspec' do
5
5
  watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
7
  watch('spec/spec_helper.rb') { "spec" }
8
8
  end
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  [![Code Climate](https://codeclimate.com/github/forresty/ttable/badges/gpa.svg)](https://codeclimate.com/github/forresty/ttable)
4
4
  [![Coverage Status](https://img.shields.io/coveralls/forresty/ttable.svg)](https://coveralls.io/r/forresty/ttable)
5
5
  [![Build Status](https://travis-ci.org/forresty/ttable.svg?branch=master)](https://travis-ci.org/forresty/ttable)
6
+ [![Gem Version](https://badge.fury.io/rb/ttable.svg)](http://badge.fury.io/rb/ttable)
6
7
 
7
8
  See it in action:
8
9
 
@@ -19,7 +19,7 @@ class String
19
19
  elsif %w{ ͡ ͜ }.include?(c)
20
20
  # zero width
21
21
  result += 0
22
- elsif %w{ ě ì • é · ♪ … ω ˊ ˋ √ “ ” ☻ ※ ◎ ◆ ‘ ★ ’ — ° ʖ ¯ ≥ ≤ ≧ ∇ ≦  ❤ ☺ ╭ ╯ ε ╰ ╮ з ∠ → ☞ ë ϵ Θ ϶ }.include?(c)
22
+ elsif %w{ ě ì • é · ♪ … ω ˊ ˋ √ “ ” ☻ ※ ◎ ◆ ‘ ★ ’ — ° ʖ ¯ ≥ ≤ ≧ ∇ ≦  ❤ ☺ ╭ ╯ ε ╰ ╮ з ∠ → ☞ ë ϵ Θ ϶ Ο Ι }.include?(c)
23
23
  result += 1
24
24
  elsif c == ' ' # ord == 8198
25
25
  result += 1
@@ -50,9 +50,10 @@ module Terminal
50
50
  @rows = []
51
51
  @headings = []
52
52
  @column_widths = []
53
-
54
53
  if object
55
- if object.respond_to?(:each)
54
+ if object.is_a?(Hash)
55
+ add_hash(object, options)
56
+ elsif object.respond_to?(:each)
56
57
  object.each { |o| add_object(o, options) }
57
58
  else
58
59
  add_object(object, options)
@@ -64,17 +65,18 @@ module Terminal
64
65
  end
65
66
 
66
67
  def add_object(object, options)
67
- if object.respond_to?(:to_hash)
68
- hash = object.to_hash
69
- if options[:only]
70
- hash.keep_if { |k, v| options[:only].map(&:to_sym).include?(k) }
71
- elsif options[:except]
72
- hash.delete_if { |k, v| options[:except].map(&:to_sym).include?(k) }
73
- end
68
+ add_hash(object.to_hash, options) if object.respond_to?(:to_hash)
69
+ end
74
70
 
75
- @headings = hash.keys.map(&:to_s)
76
- @rows << hash.values
71
+ def add_hash(hash, options)
72
+ if options[:only]
73
+ hash.keep_if { |k, v| options[:only].map(&:to_sym).include?(k) }
74
+ elsif options[:except]
75
+ hash.delete_if { |k, v| options[:except].map(&:to_sym).include?(k) }
77
76
  end
77
+
78
+ @headings = hash.keys.map(&:to_s)
79
+ @rows << hash.values
78
80
  end
79
81
 
80
82
  def headings=(headings)
@@ -1,5 +1,5 @@
1
1
  module Terminal
2
2
  class Table
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
5
5
  end
@@ -22,6 +22,38 @@ module Terminal
22
22
  describe Table do
23
23
  it { should respond_to :to_s }
24
24
 
25
+ describe 'initialize with hash' do
26
+ let(:hash) { { foo: 'bar' } }
27
+
28
+ subject { Table.new(hash) }
29
+
30
+ expected = <<END
31
+ +-----+
32
+ | foo |
33
+ +-----+
34
+ | bar |
35
+ +-----+
36
+ END
37
+ its(:to_s) { should == expected.gsub(/^(\s+)/, '') }
38
+ end
39
+
40
+ describe 'initialize with array of hashes' do
41
+ let(:hash1) { { foo: 'bar1' } }
42
+ let(:hash2) { { foo: 'bar2' } }
43
+
44
+ subject { Table.new([hash1, hash2]) }
45
+
46
+ expected = <<END
47
+ +------+
48
+ | foo |
49
+ +------+
50
+ | bar1 |
51
+ | bar2 |
52
+ +------+
53
+ END
54
+ its(:to_s) { should == expected.gsub(/^(\s+)/, '') }
55
+ end
56
+
25
57
  describe 'initialize with object#to_hash' do
26
58
  let(:object) { Dummy.new.tap { |d| d.foo = 'bar' } }
27
59
  subject { Table.new(object) }
@@ -357,5 +389,10 @@ describe String do
357
389
  subject { "ϵ( 'Θ' )϶" }
358
390
  its(:twidth) { should == 9 }
359
391
  end
392
+
393
+ context 'にΟΙ' do
394
+ subject { 'にΟΙ' }
395
+ its(:twidth) { should == 4 }
396
+ end
360
397
  end
361
398
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ttable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Forrest Ye
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-08 00:00:00.000000000 Z
11
+ date: 2014-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler