-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
executable file
·91 lines (63 loc) · 2.34 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
The idea is to have an easy way to have an updateable table to print
out to the terminal. Learn by example:
require 'rubygems'
require 'easytable'
include EasyTable
t = Table.new # Create a table
Use << to add rows, such as:
t << ['One','Two','Three'] # Add the header row
t << [10,20,30] # Add row one
t << [100,200,300] # Add another row
You can print to specified out stream:
t.out = STDOUT # Default
t.print # Print it out to STDOUT
The output is:
> One Two Three
> 10 20 30
> 100 200 300
You can update values like the following (and print them again):
t[1][1].value = 1111
t[2][2].value = 123123
t.print
The output is:
> One Two Three
> 10 1111 30
> 100 200 123123
You can change the look of cells, like the following:
t[1][1].color = Color::BLUE
t[1][1].background = Color::BLUE
t[1][1].bold = true
t[1][1].underline = true
t[1][1].blink = true
A text file won't show these differences.
To have 'print' statements update the table in place (i.e. instead of
just printing another copy), set the 'inplace' attribute:
t.inplace = true
You can set the attributes of complete rows, like (for row 3):
t[2].background = Color::BLUE
You can add mnemonics to the rows and columns, so that you aren't
indexing the values with integers. For example, take the following
table:
t = Table.from_array([[ 'Name', 'Age', 'Favorite Donut'],
[ 'Joe', 19, 'Glazed'],
['Suzy Q', 45, 'Strawberry-filled'],
[ 'Bob', 25, 'I hate donuts']])
Printing this we have
> Name | Age | Favorite Donut
> ------ | --- | -----------------
> Joe | 19 | Glazed
> Suzy Q | 45 | Strawberry-filled
> Bob | 25 | I hate donuts
By using mnemonics, such as:
t.col_mnemonics = [:name,:age,:donut]
t.row_mnemonics = [:head,:joe,:suzy_q,:bob]
We can then refer to the table cells in the following ways now (all
mean the sams):
t[1][2].value = 'Chocolate'
t[:joe][:donut].value = 'Chocolate'
t.joe.donut.value = 'Chocolate'
> Name | Age | Favorite Donut
> ------ | --- | -----------------
> Joe | 19 | Chocolate
> Suzy Q | 45 | Strawberry-filled
> Bob | 25 | I hate donuts