console_table 0.2.1 → 0.2.2
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 +4 -4
- data/README.md +1 -1
- data/console_table.gemspec +1 -1
- data/console_table_screenshot.png +0 -0
- data/lib/console_table.rb +3 -1
- data/test/test_console_table.rb +52 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 668c3bea75d37322b4d956247d640d60677182c6
|
4
|
+
data.tar.gz: 4362c0f568da256a1020868bae1c15b34754ab21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
data/console_table.gemspec
CHANGED
@@ -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.
|
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
|
data/lib/console_table.rb
CHANGED
@@ -231,7 +231,9 @@ module ConsoleTable
|
|
231
231
|
|
232
232
|
@out.print formatted
|
233
233
|
else
|
234
|
-
|
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
|
data/test/test_console_table.rb
CHANGED
@@ -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")
|