console_table 0.2.1 → 0.2.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: 0fed2d92f9592e9ed2fe3f687550473f783c6982
4
- data.tar.gz: c3d516293086bcc3734d8e21710c879225bbb5ae
3
+ metadata.gz: 668c3bea75d37322b4d956247d640d60677182c6
4
+ data.tar.gz: 4362c0f568da256a1020868bae1c15b34754ab21
5
5
  SHA512:
6
- metadata.gz: 3561143d5ced3c2bbb9464519c84f86f9aad36f8b17658202d4eaf4e49818a5583db8430af311dbb51a4fb11dcab31fc571b25100ea91c0f81997c6505cf4856
7
- data.tar.gz: 57be1e70ba595a59f7b4eb1b987f3aade12b7643462d09ae631359ca7d8a8a605a8b8688c450bb9c8afac0320ea445f2f5a0e32952223e37b136c3c7f0edf97c
6
+ metadata.gz: d03313dda6802650143631a93a7df42e672def160ab475075c92097540edc5f617d3b811cfb80ee60b91d5123070d34e28902acf6e6f0e1926e2fdfb95d876af
7
+ data.tar.gz: 3e96bdee594c595645402385863345487dc5f3285f78e11cd6557293e021c02283e73f392513f2a1bfb0055d4ce4e2eb4c29a93e8e53b1a9ebb989aeeee772b6
data/README.md CHANGED
@@ -12,7 +12,7 @@ It can be used to generate output similar to this screenshot:
12
12
 
13
13
  You're able to specify left/right/center text justification, headers, footers, and most importantly different sizes including exact character widths, screen percentages, and `*` for whatever is left. If the window resizes the class will notice and output all new lines with recalculated locations (previous lines are not re-printed).
14
14
 
15
- **Note**: This project is _not_ like `hirb` and it makes no attempt to take any sort of ActiveRecord objects or an array of data and automatically fit the data to a nice table. It gives much, much more control over to the developer in how the output is formatted, but is much more difficult to work with as a trade-off - you will have to go through each element of your data set and manually munge it into the format needed by ConsoleTable to print a line. ConsoleTable is meant to save on a lot of math and calculation, but will do no analyzing of your data itself in order to format it, please consult the Usage section for more details.
15
+ **Note**: This project is _not_ like `hirb` or [`console-text-formatter`](https://github.com/cjfinc/console-text-formatter)and it makes no attempt to take any sort of ActiveRecord objects or an array of hashes and automatically fit the data to a nice table. It gives much, much more control over to the developer in how the output is formatted, but is much more difficult to work with as a trade-off. ConsoleTable is meant to save on a lot of math and calculation, but will do no analyzing of your data itself in order to format it, and it will never print wider than your console window. Data is printed as rows are added, ConsoleTable doesn't "wait" until it has all the data to figure out optimal sizes for columns. Please read the Usage section carefully for examples.
16
16
 
17
17
 
18
18
  ## Installation
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "console_table"
7
- spec.version = "0.2.1"
7
+ spec.version = "0.2.2"
8
8
  spec.authors = ["Rod Hilton"]
9
9
  spec.email = ["consoletable@rodhilton.com"]
10
10
  spec.summary = %q{Simplifies printing tables of information to commandline consoles}
Binary file
@@ -231,7 +231,9 @@ module ConsoleTable
231
231
 
232
232
  @out.print formatted
233
233
  else
234
- @out.print format(column[:size], normalize(to_print.to_s))
234
+ text = to_print.to_s
235
+ justify = infer_justify_from_string(text, justify)
236
+ @out.print format(column[:size], normalize(text), ellipsize, justify)
235
237
  end
236
238
 
237
239
  if @borders
@@ -1419,6 +1419,58 @@ This is way too long and will
1419
1419
  assert_output_equal expected, @mock_out.string
1420
1420
  end
1421
1421
 
1422
+ class Fake
1423
+ def initialize(id)
1424
+ @fake_id = id
1425
+ end
1426
+
1427
+ def to_s
1428
+ "Fake: #{@fake_id}"
1429
+ end
1430
+ end
1431
+
1432
+ def test_justify_and_ellipsize_non_strings_or_hashes
1433
+
1434
+ layout = [
1435
+ {:size=>8, :title=>"Column 1", :ellipsize=>true},
1436
+ {:size=>8, :title=>"Column 2", :justify=>:right}
1437
+ ]
1438
+
1439
+ ConsoleTable.define(layout, :width => 20, :output => @mock_out) do |table|
1440
+ table << [
1441
+ :this_is_a_super_long_symbol_that_should_get_cut_off,
1442
+ :right
1443
+ ]
1444
+
1445
+ table << [
1446
+ 912376409123648791,
1447
+ 23423
1448
+ ]
1449
+
1450
+ table << [
1451
+ 0.39712390487191234,
1452
+ 0.12
1453
+ ]
1454
+
1455
+ table << [
1456
+ Fake.new(341928374134),
1457
+ Fake.new(1)
1458
+ ]
1459
+ end
1460
+
1461
+ expected=<<-END
1462
+ =================
1463
+ Column 1 Column 2
1464
+ -----------------
1465
+ this_... right
1466
+ 91237... 23423
1467
+ 0.397... 0.12
1468
+ Fake:... Fake: 1
1469
+ =================
1470
+ END
1471
+ assert_output_equal expected, @mock_out.string
1472
+ end
1473
+
1422
1474
  private
1423
1475
  def assert_output_equal(expected, actual)
1424
1476
  expected_lines = expected.split("\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rod Hilton