tabulo 0.2.0 → 0.2.1

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: 02a658d45fe5df2a6b02a39ff1ef8b85b9406a5d
4
- data.tar.gz: 1edee8575e0098a1d5b383f596ff8ef77e3916a0
3
+ metadata.gz: 1dc99325b75930d06ef7865ccf9cf88149040598
4
+ data.tar.gz: 1fbcea2102de94f56ba29d7d763db7b4e164fd10
5
5
  SHA512:
6
- metadata.gz: 2d76f4fd33ede6de1a466affd190c6377f8e0a29b2c3986c7c4c83c0ac8001b285f880589d5a74668b572e8219c570f3aaa391b0dd8839f89c478f58b9bbc5f2
7
- data.tar.gz: c4766b9abff559fd30f65356731e18311984b459bd67e11b7dc308bf93c92a2fab4902c6ea0c13bab81ffe5459df134074d93b2beec3ec26af8d8b5a4f4899df
6
+ metadata.gz: b106d3d9c33e003bba7ad38065c54ba25a7f348d58bd20b5508dd512d6fb0a0600f89ba7c4a5f8239736ff2add5a490ae0d7f6bf5952a21e2fc8a80176ea2091
7
+ data.tar.gz: f50e7092a449944c3bff02fe8ee5a477bb94b3b5ef80232f12aa1ec4a397ed43e47011b8cc45856d847a33616c00dd0ed6e371092479d48ae95808f0a9838843
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  **/.*.swp
11
+ coverage
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.5
5
- before_install: gem install bundler -v 1.13.7
4
+ - 2.2.0
5
+ - 2.3.1
6
+ before_install: gem install bundler -v 1.14.6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+
4
+ ## v0.2.1
5
+
6
+ * Code tidy-ups
7
+ * Tidy-ups and improvements to README, including adding badges for test coverage etc..
8
+
3
9
  ## v0.2.0
4
10
 
5
11
  * Allow columns to be initialized with `columns` option in `Table` initializer
data/README.md CHANGED
@@ -1,10 +1,20 @@
1
1
  # Tabulo
2
2
 
3
+ [![Gem Version][GV img]][Gem Version]
4
+ [![Build Status][BS img]][Build Status]
5
+ [![Dependency Status][DS img]][Dependency Status]
6
+ [![Coverage Status][CS img]][Coverage Status]
7
+
3
8
  ## Overview
4
9
 
5
10
  Tabulo generates ASCII tables.
6
11
 
7
- A `Tabulo::Table` can, of course, be printed:
12
+ ```ruby
13
+ table = Tabulo::Table.new([1, 2, 50000000]) do |t|
14
+ t.add_column("N", &:itself)
15
+ t.add_column("Doubled") { |n| n * 2 }
16
+ end
17
+ ```
8
18
 
9
19
  ```
10
20
  > puts table
@@ -16,7 +26,7 @@ A `Tabulo::Table` can, of course, be printed:
16
26
  | 50000000 | 10000000 |
17
27
  ```
18
28
 
19
- But it is also `Enumerable`, so you can process one row at a time:
29
+ A `Tabulo::Table` is an `Enumerable`, so you can process one row at a time:
20
30
 
21
31
  ```ruby
22
32
  table.each do |row|
@@ -25,7 +35,7 @@ table.each do |row|
25
35
  end
26
36
  ```
27
37
 
28
- And rows are themselves `Enumerable`, providing access to the underlying cell values:
38
+ Each `Tabulo::Row` is also an `Enumerable`, which provides access to the underlying cell values:
29
39
 
30
40
  ```ruby
31
41
  table.each do |row|
@@ -79,11 +89,9 @@ end
79
89
  Or equivalently:
80
90
 
81
91
  ```ruby
82
- Tabulo::Table.new([1, 2, 5], columns: %i(itself even odd))
92
+ Tabulo::Table.new([1, 2, 5], columns: %i(itself even? odd?))
83
93
  ```
84
94
 
85
- The resulting table looks like this:
86
-
87
95
  ```
88
96
  > puts table
89
97
  +----------+----------+----------+
@@ -102,7 +110,7 @@ the header text:
102
110
  table = Tabulo::Table.new([1, 2, 5]) do |t|
103
111
  t.add_column("N", &:itself)
104
112
  t.add_column("Doubled") { |n| n * 2 }
105
- t.add_column(:odd?) # we can mix and match
113
+ t.add_column(:odd?)
106
114
  end
107
115
  ```
108
116
 
@@ -258,3 +266,12 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/matt-h
258
266
  The gem is available as open source under the terms of the [MIT
259
267
  License](http://opensource.org/licenses/MIT).
260
268
 
269
+ [Gem Version]: https://rubygems.org/gems/tabulo
270
+ [Build Status]: https://travis-ci.org/matt-harvey/tabulo
271
+ [Dependency Status]: https://gemnasium.com/matt-harvey/tabulo
272
+ [Coverage Status]: https://coveralls.io/r/matt-harvey/tabulo
273
+
274
+ [GV img]: https://img.shields.io/gem/v/tabulo.svg
275
+ [BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg
276
+ [DS img]: https://img.shields.io/gemnasium/matt-harvey/tabulo.svg
277
+ [CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg
data/lib/tabulo/column.rb CHANGED
@@ -13,9 +13,6 @@ module Tabulo
13
13
 
14
14
  # TODO Should be able to set these default on a Table-by-Table basis.
15
15
  @width = options[:width] || Table::DEFAULT_COLUMN_WIDTH
16
-
17
- @horizontal_rule_character =
18
- options[:horizontal_rule_character] || Table::DEFAULT_HORIZONTAL_RULE_CHARACTER
19
16
  end
20
17
 
21
18
  def header_cell
@@ -23,7 +20,7 @@ module Tabulo
23
20
  end
24
21
 
25
22
  def horizontal_rule
26
- @horizontal_rule_character * @width
23
+ Table::HORIZONTAL_RULE_CHARACTER * @width
27
24
  end
28
25
 
29
26
  def body_cell(source)
@@ -50,8 +47,6 @@ module Tabulo
50
47
  [0, padding]
51
48
  when :right
52
49
  [padding, 0]
53
- else
54
- raise "Unrecognized alignment: #{real_alignment}"
55
50
  end
56
51
 
57
52
  "#{' ' * left_padding}#{content}#{' ' * right_padding}"
data/lib/tabulo/table.rb CHANGED
@@ -4,7 +4,8 @@ module Tabulo
4
4
  include Enumerable
5
5
 
6
6
  DEFAULT_COLUMN_WIDTH = 8
7
- DEFAULT_HORIZONTAL_RULE_CHARACTER = "-"
7
+ HORIZONTAL_RULE_CHARACTER = "-"
8
+ CORNER_CHARACTER = "+"
8
9
 
9
10
  attr_reader :columns
10
11
 
@@ -24,41 +25,15 @@ module Tabulo
24
25
  @wrap_body_cells_to = opts[:wrap_body_cells_to]
25
26
  @sources = sources
26
27
  @joiner = "|"
27
- @corner_character = "+"
28
- @horizontal_rule_character = "-"
29
28
  @truncation_indicator = "~"
30
29
  @padding_character = " "
31
30
  @default_column_width = DEFAULT_COLUMN_WIDTH
32
- @columns = opts[:columns].map do |item|
33
- case item
34
- when Column
35
- item
36
- else
37
- Column.new({
38
- label: item.to_sym,
39
- header: item.to_s,
40
- align_header: :center,
41
- horizontal_rule_character: @horizontal_rule_character,
42
- width: @default_column_width,
43
- formatter: :to_s.to_proc
44
- })
45
- end
46
- end
31
+ @columns = opts[:columns].map { |item| make_column(item) }
47
32
  yield self if block_given?
48
33
  end
49
34
 
50
35
  def add_column(label, options = {}, &extractor)
51
- @columns << Column.new({
52
- label: label.to_sym,
53
- header: label.to_s,
54
- truncate: true,
55
- align_header: :center,
56
- horizontal_rule_character: @horizontal_rule_character,
57
- width: @default_column_width,
58
- extractor: extractor || (label.respond_to?(:to_proc) ? label.to_proc : proc { nil }),
59
- formatter: :to_s.to_proc
60
-
61
- }.merge(options))
36
+ @columns << make_column(label, extractor: extractor)
62
37
  end
63
38
 
64
39
  def to_s
@@ -85,7 +60,7 @@ module Tabulo
85
60
  end
86
61
 
87
62
  def horizontal_rule
88
- format_row(false, @horizontal_rule_character, @corner_character, &:horizontal_rule)
63
+ format_row(false, HORIZONTAL_RULE_CHARACTER, CORNER_CHARACTER, &:horizontal_rule)
89
64
  end
90
65
 
91
66
  def formatted_body_row(source, options = { with_header: false })
@@ -135,5 +110,21 @@ module Tabulo
135
110
  def join_lines(lines)
136
111
  lines.join($/) # join strings with cross-platform newline
137
112
  end
113
+
114
+ def make_column(item, options = { })
115
+ case item
116
+ when Column
117
+ item
118
+ else
119
+ Column.new({
120
+ label: item.to_sym,
121
+ header: item.to_s,
122
+ align_header: :center,
123
+ width: @default_column_width,
124
+ formatter: :to_s.to_proc
125
+
126
+ }.merge(options))
127
+ end
128
+ end
138
129
  end
139
130
  end
@@ -1,3 +1,3 @@
1
1
  module Tabulo
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/tabulo.gemspec CHANGED
@@ -21,7 +21,11 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.required_ruby_version = "~> 2.0"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.14.6"
25
27
  spec.add_development_dependency "rake", "~> 10.0"
26
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "simplecov"
30
+ spec.add_development_dependency "coveralls"
27
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabulo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Harvey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-22 00:00:00.000000000 Z
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: 1.14.6
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: 1.14.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Enumerable ASCII table
56
84
  email:
57
85
  - software@matthewharvey.net
@@ -85,9 +113,9 @@ require_paths:
85
113
  - lib
86
114
  required_ruby_version: !ruby/object:Gem::Requirement
87
115
  requirements:
88
- - - ">="
116
+ - - "~>"
89
117
  - !ruby/object:Gem::Version
90
- version: '0'
118
+ version: '2.0'
91
119
  required_rubygems_version: !ruby/object:Gem::Requirement
92
120
  requirements:
93
121
  - - ">="