tabulo 0.6.1 → 0.6.2

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: 1e98d88f8794a4a99a88e7b03ddd98cde4800a1d
4
- data.tar.gz: 7cd37619d53da0c9914e6dce651dd56cb427d182
3
+ metadata.gz: 5a2f88a15024f1728f244d9f72a14b6f88a893fc
4
+ data.tar.gz: c6f23f4a1568575083122f501d2e61492057b2b7
5
5
  SHA512:
6
- metadata.gz: d8c1ee3777ad66c2e28475798f3d565f830c583110ab02ca47f7bab9308f826cc877487569ce9a9f13b7578e74c9e237998d8c36dbca9016835fdff0dc0f8980
7
- data.tar.gz: 9782a06e2877da5aa7d6ba3ecb827f5915b217beb50b02f97684705aaf5ce6fb0d9614cbb9a6592c049ad16da7cc09777176349af172059daf7edc4a0abe5d35
6
+ metadata.gz: 703ef06a5ea3c9c0dbf1b01b1572b02f0eca2e9ef6dc64508cb7a93459211c1c420f32af29c95a22581dd31c6a02ed3308ee7e913dfa37be65cf592633650b14
7
+ data.tar.gz: f17355d77642115e8bca70c5601164dfe16e186d1b5c79e3577d1e292eda46942a1fd9f0f9ccd730bbedaf2c4ce2a526832425715ae0c6d13e11a470ff018a2c
data/.travis.yml CHANGED
@@ -1,6 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.2.0
5
- - 2.3.1
4
+ - 2.1.10
5
+ - 2.2.6
6
+ - 2.3.3
7
+ - 2.4.0
6
8
  before_install: gem install bundler -v 1.14.6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### v0.6.2
4
+
5
+ * Explicitly support only Ruby >= 2.1.10.
6
+
3
7
  ### v0.6.1
4
8
 
5
9
  * Fix Table#shrinkwrap! handling of newlines within header cell content.
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Tabulo
2
2
 
3
3
  [![Gem Version][GV img]][Gem Version]
4
- [![Build Status][BS img]][Build Status]
5
4
  [![Dependency Status][DS img]][Dependency Status]
6
5
  [![Coverage Status][CS img]][Coverage Status]
6
+ [![Build Status][BS img]][Build Status]
7
7
  [![Code Climate][CC img]][Code Climate]
8
+ [![Documentation][DC img]][Documentation]
8
9
 
9
10
  ## Overview
10
11
 
@@ -29,11 +30,11 @@ end
29
30
 
30
31
  ## Features
31
32
 
32
- * Set [fixed widths](#fixed-column-widths) on individual columns, then either [wrap](#overflow-handling) or
33
+ * Set [fixed column widths](#fixed-column-widths), then either [wrap](#overflow-handling) or
33
34
  [truncate](#overflow-handling) the overflow.
34
- * Alternatively, [shrinkwrap](#shrinkwrap) the table so that each column is just wide enough for its
35
- contents.
36
- * Put an upper limit on table width when shrinkwrapping, to [stop it overflowing your terminal horizontally](#max-table-width).
35
+ * Alternatively, [shrinkwrap](#shrinkwrap) the table so that each column is just wide enough for its contents.
36
+ * Put an upper limit on total table width when shrinkwrapping, to
37
+ [stop it overflowing your terminal horizontally](#max-table-width).
37
38
  * Alignment of cell content is [configurable](#cell-alignment), but has helpful content-based defaults
38
39
  (numbers right, strings left).
39
40
  * Headers are [repeatable](#repeating-headers).
@@ -390,9 +391,11 @@ License](http://opensource.org/licenses/MIT).
390
391
  [Dependency Status]: https://gemnasium.com/matt-harvey/tabulo
391
392
  [Coverage Status]: https://coveralls.io/r/matt-harvey/tabulo
392
393
  [Code Climate]: https://codeclimate.com/github/matt-harvey/tabulo
393
-
394
- [GV img]: https://img.shields.io/gem/v/tabulo.svg
395
- [BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg
396
- [DS img]: https://img.shields.io/gemnasium/matt-harvey/tabulo.svg
397
- [CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg
398
- [CC img]: https://img.shields.io/codeclimate/github/matt-harvey/tabulo.svg
394
+ [Documentation]: http://www.rubydoc.info/gems/tabulo/0.6.2
395
+
396
+ [GV img]: https://img.shields.io/gem/v/tabulo.svg?style=plastic
397
+ [BS img]: https://img.shields.io/travis/matt-harvey/tabulo.svg?style=plastic
398
+ [DS img]: https://img.shields.io/gemnasium/matt-harvey/tabulo.svg?style=plastic
399
+ [CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg?style=plastic
400
+ [CC img]: https://img.shields.io/codeclimate/github/matt-harvey/tabulo.svg?style=plastic
401
+ [DC img]: https://img.shields.io/badge/docs-v0.6.2-blue.svg?style=plastic
data/Rakefile CHANGED
@@ -1,6 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require 'rake-version'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
7
  task :default => :spec
8
+
9
+ RakeVersion::Tasks.new do |v|
10
+ v.copy "lib/tabulo/version.rb"
11
+ v.copy "README.md", all: true
12
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.6.2
data/lib/tabulo/row.rb CHANGED
@@ -40,12 +40,10 @@ module Tabulo
40
40
 
41
41
  # @return a Hash representation of the {Row}, with column labels acting
42
42
  # as keys and the calculated cell values (before formatting) providing the values.
43
- #
44
43
  # @example
45
44
  # table = Tabulo::Table.new([1, 10], columns: %i(itself even?))
46
45
  # row = table.first
47
46
  # row.to_h # => { :itself => 1, :even? => false }
48
- #
49
47
  def to_h
50
48
  @table.columns.map(&:label).zip(to_a).to_h
51
49
  end
data/lib/tabulo/table.rb CHANGED
@@ -7,9 +7,11 @@ module Tabulo
7
7
  include Enumerable
8
8
 
9
9
  DEFAULT_COLUMN_WIDTH = 12
10
-
11
10
  HORIZONTAL_RULE_CHARACTER = "-"
11
+ VERTICAL_RULE_CHARACTER = "|"
12
12
  CORNER_CHARACTER = "+"
13
+ PADDING_CHARACTER = " "
14
+ TRUNCATION_INDICATOR = "~"
13
15
 
14
16
  # @!visibility private
15
17
  attr_reader :columns
@@ -33,7 +35,6 @@ module Tabulo
33
35
  # headers), if their content is longer than the column's fixed width. If passed <tt>nil</tt>, content will
34
36
  # be wrapped for as many rows as required to accommodate it. If passed a Fixnum N (> 0), content will be
35
37
  # wrapped up to N rows and then truncated thereafter.
36
- #
37
38
  # @return [Table] a new Table
38
39
  def initialize(sources, columns: [], column_width: nil, header_frequency: :start,
39
40
  wrap_header_cells_to: nil, wrap_body_cells_to: nil)
@@ -45,10 +46,6 @@ module Tabulo
45
46
 
46
47
  @default_column_width = (column_width || DEFAULT_COLUMN_WIDTH)
47
48
 
48
- @joiner = "|"
49
- @truncation_indicator = "~"
50
- @padding_character = " "
51
-
52
49
  @columns = []
53
50
  columns.each { |item| add_column(item) }
54
51
 
@@ -62,7 +59,6 @@ module Tabulo
62
59
  # extractor argument is not also provided, then the label argument should correspond to
63
60
  # a method to be called on each item in the table sources to provide the content
64
61
  # for this column.
65
- #
66
62
  # @param [nil, #to_s] header (nil) Text to be displayed in the column header. If passed nil,
67
63
  # the column's label will also be used as its header text.
68
64
  # @param [:left, :center, :right] align_header (:center) Specifies how the header text
@@ -85,7 +81,6 @@ module Tabulo
85
81
  # that will be passed each of the Table sources to determine the value in each cell of this
86
82
  # column. If this is not provided, then the column label will be treated as a method to be
87
83
  # called on each source item to determine each cell's value.
88
- #
89
84
  def add_column(label, header: nil, align_header: :center, align_body: nil,
90
85
  width: nil, formatter: :to_s.to_proc, &extractor)
91
86
 
@@ -136,12 +131,12 @@ module Tabulo
136
131
 
137
132
  # @return [String] an "ASCII" graphical representation of the Table column headers.
138
133
  def formatted_header
139
- format_row(@wrap_header_cells_to, &:header_subcells)
134
+ cells = @columns.map(&:header_subcells)
135
+ format_row(cells, @wrap_header_cells_to)
140
136
  end
141
137
 
142
138
  # @return [String] an "ASCII" graphical representation of a horizontal
143
139
  # dividing line suitable for printing at any point in the table.
144
- #
145
140
  # @example Print a horizontal divider after every row:
146
141
  # table.each do |row|
147
142
  # puts row
@@ -173,7 +168,6 @@ module Tabulo
173
168
  # in each column, together with border characters (1 on each side of the table and 1 between
174
169
  # adjacent columns). I.e. there is a certain width below width the Table will refuse to
175
170
  # shrink itself.
176
- #
177
171
  # @return [Table] the Table itself
178
172
  def shrinkwrap!(max_table_width: nil)
179
173
  return self if columns.none?
@@ -218,7 +212,8 @@ module Tabulo
218
212
 
219
213
  # @!visibility private
220
214
  def formatted_body_row(source, with_header: false)
221
- inner = format_row(@wrap_body_cells_to) { |column| column.body_subcells(source) }
215
+ cells = @columns.map { |column| column.body_subcells(source) }
216
+ inner = format_row(cells, @wrap_body_cells_to)
222
217
  if with_header
223
218
  join_lines([horizontal_rule, formatted_header, horizontal_rule, inner])
224
219
  else
@@ -235,52 +230,44 @@ module Tabulo
235
230
 
236
231
  # @!visibility private
237
232
  #
238
- # Yields each column to passed block, then wraps and joins the results to form
239
- # a formatted row.
240
- def format_row(wrap_cells_to)
241
-
242
- # Create an array of "cell stacks", each of which is an array of strings that
243
- # will be stacked on top of each other to form a wrapped cell.
244
- cell_stacks = @columns.map do |column|
245
-
246
- # Get the raw, non-wrapped, non-truncated content of the cell.
247
- raw_subcells = yield column
248
-
249
- num_raw_subcells = raw_subcells.size
250
- num_wrapped_subcells = (wrap_cells_to || num_raw_subcells)
251
-
252
- truncated = (num_raw_subcells > num_wrapped_subcells)
253
- subcells = raw_subcells[0...num_wrapped_subcells]
254
-
255
- subcells.map.with_index do |subcell, i|
256
- subcell_truncated = (truncated && (i == subcells.size - 1))
257
- lpad = @padding_character
258
- rpad = (subcell_truncated ? @truncation_indicator : @padding_character)
259
- "#{lpad}#{subcell}#{rpad}"
233
+ # Formats a single header row or body row as a String.
234
+ #
235
+ # @param [String[][]] cells an Array of Array-of-Strings, each of which represents a
236
+ # "stack" of "subcells". Each such stack represents the wrapped content of a given
237
+ # "cell" in this row, from the top down, one String for each "line".
238
+ # Each String includes the spaces, if any, on either side required for the
239
+ # "internal padding" of the cell to carry out the cell content alignment -- but
240
+ # does not include the single character of padding around each column.
241
+ # @param [Fixnum] wrap_cells_to the number of "lines" of wrapped content to allow
242
+ # before truncating.
243
+ # @return [String] the entire formatted row including all padding and borders.
244
+ def format_row(cells, wrap_cells_to)
245
+ row_height = ([wrap_cells_to, cells.map(&:size).max].compact.min || 1)
246
+
247
+ subrows = (0...row_height).map do |subrow_index|
248
+ subrow_components = cells.map.with_index do |cell, column_index|
249
+ num_subcells = cell.size
250
+ cell_truncated = (num_subcells > row_height)
251
+ append_truncator = (cell_truncated && subrow_index + 1 == row_height)
252
+
253
+ lpad = PADDING_CHARACTER
254
+ rpad = (append_truncator ? TRUNCATION_INDICATOR : PADDING_CHARACTER)
255
+
256
+ inner =
257
+ if subrow_index < num_subcells
258
+ cell[subrow_index]
259
+ else
260
+ column_width = @columns[column_index].width
261
+ PADDING_CHARACTER * column_width
262
+ end
263
+
264
+ "#{lpad}#{inner}#{rpad}"
260
265
  end
261
- end
262
266
 
263
- max_cell_stack_height = cell_stacks.map(&:size).max || 1
264
-
265
- # A subrow is a string representing a single horizontal slice of this row that's
266
- # strictly one character high.
267
- subrows = (0...max_cell_stack_height).map do |subrow_index|
268
- cell_stacks.map.with_index do |cell_stack, column_index|
269
- if subrow_index < cell_stack.size
270
- # This cell stack is at least as "deep" as the subrow we're on. So just
271
- # grab the subcell for this subrow from this cell stack.
272
- cell_stack[subrow_index]
273
- else
274
- # This cell stack is not "deep" enough. So we make an empty subcell to
275
- # add to this subrow for this column
276
- surround(' ' * @columns[column_index].width, @padding_character)
277
- end
278
- end
267
+ surround_join(subrow_components, VERTICAL_RULE_CHARACTER)
279
268
  end
280
269
 
281
- # Join each subrow with border characters, then join these with newlines, to form
282
- # the wrapped, formatted row as a single string.
283
- join_lines(subrows.map { |subrow| surround_join(subrow, @joiner) })
270
+ join_lines(subrows)
284
271
  end
285
272
 
286
273
  # @!visibility private
@@ -1,3 +1,3 @@
1
1
  module Tabulo
2
- VERSION = "0.6.1"
2
+ VERSION = "0.6.2"
3
3
  end
data/tabulo.gemspec CHANGED
@@ -21,14 +21,15 @@ 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.required_ruby_version = "~> 2.0"
24
+ spec.required_ruby_version = ">= 2.1.10"
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.14.6"
27
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rake", "~> 11.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  spec.add_development_dependency "simplecov"
30
30
  spec.add_development_dependency "coveralls"
31
31
  spec.add_development_dependency "yard"
32
32
  spec.add_development_dependency "redcarpet"
33
33
  spec.add_development_dependency "github-markup"
34
+ spec.add_development_dependency "rake-version", "~> 1.0"
34
35
  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.6.1
4
+ version: 0.6.2
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-05-03 00:00:00.000000000 Z
11
+ date: 2017-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '11.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '11.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake-version
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '1.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '1.0'
125
139
  description: Enumerable ASCII table
126
140
  email:
127
141
  - software@matthewharvey.net
@@ -140,6 +154,7 @@ files:
140
154
  - LICENSE.txt
141
155
  - README.md
142
156
  - Rakefile
157
+ - VERSION
143
158
  - bin/console
144
159
  - bin/setup
145
160
  - lib/tabulo.rb
@@ -158,9 +173,9 @@ require_paths:
158
173
  - lib
159
174
  required_ruby_version: !ruby/object:Gem::Requirement
160
175
  requirements:
161
- - - "~>"
176
+ - - ">="
162
177
  - !ruby/object:Gem::Version
163
- version: '2.0'
178
+ version: 2.1.10
164
179
  required_rubygems_version: !ruby/object:Gem::Requirement
165
180
  requirements:
166
181
  - - ">="