cft_smartcloud 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG +11 -0
  3. data/README.md +106 -0
  4. data/VERSION +1 -1
  5. data/bin/cft_smartcloud +33 -7
  6. data/bin/smartcloud +33 -7
  7. data/cft_smartcloud.gemspec +84 -20
  8. data/lib/config/config.yml +2 -0
  9. data/lib/curl_client.rb +42 -0
  10. data/lib/rest-client-1.6.6-master/.gitignore +6 -0
  11. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/README.rdoc +10 -1
  12. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/Rakefile +0 -0
  13. data/lib/rest-client-1.6.6-master/VERSION +1 -0
  14. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/bin/restclient +5 -4
  15. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/history.md +22 -0
  16. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/rest-client.rb +0 -0
  17. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/rest_client.rb +0 -0
  18. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/abstract_response.rb +0 -0
  19. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/exceptions.rb +0 -0
  20. data/lib/rest-client-1.6.6-master/lib/restclient/net_http_ext.rb +55 -0
  21. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/payload.rb +17 -2
  22. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/raw_response.rb +0 -0
  23. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/request.rb +21 -19
  24. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/resource.rb +0 -0
  25. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient/response.rb +0 -0
  26. data/lib/{rest-client-1.6.3 → rest-client-1.6.6-master}/lib/restclient.rb +0 -0
  27. data/lib/rest-client-1.6.6-master/rest-client.gemspec +76 -0
  28. data/lib/rest-client-1.6.6-master/spec/abstract_response_spec.rb +85 -0
  29. data/lib/rest-client-1.6.6-master/spec/base.rb +16 -0
  30. data/lib/rest-client-1.6.6-master/spec/exceptions_spec.rb +98 -0
  31. data/lib/rest-client-1.6.6-master/spec/integration/certs/equifax.crt +19 -0
  32. data/lib/rest-client-1.6.6-master/spec/integration/certs/verisign.crt +14 -0
  33. data/lib/rest-client-1.6.6-master/spec/integration/request_spec.rb +25 -0
  34. data/lib/rest-client-1.6.6-master/spec/integration_spec.rb +38 -0
  35. data/lib/rest-client-1.6.6-master/spec/master_shake.jpg +0 -0
  36. data/lib/rest-client-1.6.6-master/spec/payload_spec.rb +234 -0
  37. data/lib/rest-client-1.6.6-master/spec/raw_response_spec.rb +17 -0
  38. data/lib/rest-client-1.6.6-master/spec/request2_spec.rb +40 -0
  39. data/lib/rest-client-1.6.6-master/spec/request_spec.rb +536 -0
  40. data/lib/rest-client-1.6.6-master/spec/resource_spec.rb +134 -0
  41. data/lib/rest-client-1.6.6-master/spec/response_spec.rb +169 -0
  42. data/lib/rest-client-1.6.6-master/spec/restclient_spec.rb +73 -0
  43. data/lib/slop-2.3.1/.gemtest +0 -0
  44. data/lib/slop-2.3.1/.gitignore +6 -0
  45. data/lib/slop-2.3.1/.yardopts +6 -0
  46. data/lib/slop-2.3.1/CHANGES.md +137 -0
  47. data/lib/slop-2.3.1/LICENSE +20 -0
  48. data/lib/slop-2.3.1/README.md +293 -0
  49. data/lib/slop-2.3.1/Rakefile +6 -0
  50. data/lib/slop-2.3.1/lib/slop.rb +1022 -0
  51. data/lib/slop-2.3.1/slop.gemspec +11 -0
  52. data/lib/slop-2.3.1/test/commands_test.rb +151 -0
  53. data/lib/slop-2.3.1/test/helper.rb +13 -0
  54. data/lib/slop-2.3.1/test/option_test.rb +198 -0
  55. data/lib/slop-2.3.1/test/slop_test.rb +574 -0
  56. data/lib/smartcloud.rb +186 -116
  57. data/lib/terminal-table-1.4.4/History.rdoc +53 -0
  58. data/lib/terminal-table-1.4.4/Manifest +24 -0
  59. data/lib/terminal-table-1.4.4/README.rdoc +240 -0
  60. data/lib/terminal-table-1.4.4/Rakefile +15 -0
  61. data/lib/terminal-table-1.4.4/Todo.rdoc +14 -0
  62. data/lib/terminal-table-1.4.4/examples/examples.rb +80 -0
  63. data/lib/terminal-table-1.4.4/lib/terminal-table/cell.rb +88 -0
  64. data/lib/terminal-table-1.4.4/lib/terminal-table/core_ext.rb +8 -0
  65. data/lib/terminal-table-1.4.4/lib/terminal-table/import.rb +4 -0
  66. data/lib/terminal-table-1.4.4/lib/terminal-table/row.rb +48 -0
  67. data/lib/terminal-table-1.4.4/lib/terminal-table/separator.rb +14 -0
  68. data/lib/terminal-table-1.4.4/lib/terminal-table/style.rb +61 -0
  69. data/lib/terminal-table-1.4.4/lib/terminal-table/table.rb +217 -0
  70. data/lib/terminal-table-1.4.4/lib/terminal-table/table_helper.rb +9 -0
  71. data/lib/terminal-table-1.4.4/lib/terminal-table/version.rb +6 -0
  72. data/lib/terminal-table-1.4.4/lib/terminal-table.rb +27 -0
  73. data/lib/terminal-table-1.4.4/spec/cell_spec.rb +54 -0
  74. data/lib/terminal-table-1.4.4/spec/core_ext_spec.rb +18 -0
  75. data/lib/terminal-table-1.4.4/spec/import_spec.rb +11 -0
  76. data/lib/terminal-table-1.4.4/spec/spec.opts +1 -0
  77. data/lib/terminal-table-1.4.4/spec/spec_helper.rb +8 -0
  78. data/lib/terminal-table-1.4.4/spec/table_spec.rb +525 -0
  79. data/lib/terminal-table-1.4.4/tasks/docs.rake +13 -0
  80. data/lib/terminal-table-1.4.4/tasks/gemspec.rake +3 -0
  81. data/lib/terminal-table-1.4.4/tasks/spec.rake +25 -0
  82. data/lib/terminal-table-1.4.4/terminal-table.gemspec +30 -0
  83. data/responses/addresses +26 -0
  84. data/responses/addresses.blank +2 -0
  85. data/responses/instances +74 -0
  86. data/responses/keys +33 -0
  87. data/responses/locations +142 -0
  88. data/responses/offerings_image +3780 -0
  89. data/responses/storage +379 -0
  90. metadata +86 -22
  91. data/README.rdoc +0 -75
  92. data/lib/rest-client-1.6.3/VERSION +0 -1
  93. data/lib/rest-client-1.6.3/lib/restclient/net_http_ext.rb +0 -21
@@ -0,0 +1,53 @@
1
+ 1.4.4 / 2011-11-07
2
+ ==================
3
+
4
+ * Add support for multi-line rows, table titles, and colors
5
+
6
+ 1.4.3 / 2011-10-13
7
+ ==================
8
+
9
+ * Optimize for faster table output.
10
+
11
+ 1.4.2 / 2010-01-14
12
+ ==================
13
+
14
+ * Fixed some bugs with colspan
15
+
16
+ === 1.4.1 / 2009-12-18
17
+
18
+ * Fix column alignment with separators.
19
+
20
+ === 1.4.0 / 2009-12-18
21
+
22
+ * Can now add :seperator arbitrarily in a table [thanks splattael]
23
+ * Fix common typo: seperator -> separator [thanks splattael]
24
+
25
+ === 1.3.0 / 2009-10-16
26
+
27
+ * Major refactoring (functionality remains the same)
28
+
29
+ === 1.2.0 / 2009-08-06
30
+
31
+ * Added colspan support to table
32
+
33
+ === 1.1.0 / 2009-08-06
34
+
35
+ * Added colspan support to table
36
+
37
+ === 1.1.0 / 2009-07-13
38
+
39
+ * Added Table#==
40
+
41
+ === 1.0.5 / 2009-03-14
42
+
43
+ * Allowing nil to be passed to table for headings
44
+ * Revised doc to show that rows can be splatted now
45
+ * Misc refactoring
46
+
47
+ === 1.0.3 / 2009-01-15
48
+
49
+ * Moved yield or eval to Terminal::Table initialize where it belongs
50
+
51
+ === 1.0.0 / 2009-01-13
52
+
53
+ * Initial release
@@ -0,0 +1,24 @@
1
+ History.rdoc
2
+ Manifest
3
+ README.rdoc
4
+ Rakefile
5
+ Todo.rdoc
6
+ examples/examples.rb
7
+ lib/terminal-table.rb
8
+ lib/terminal-table/cell.rb
9
+ lib/terminal-table/core_ext.rb
10
+ lib/terminal-table/heading.rb
11
+ lib/terminal-table/import.rb
12
+ lib/terminal-table/table.rb
13
+ lib/terminal-table/table_helper.rb
14
+ lib/terminal-table/version.rb
15
+ spec/cell_spec.rb
16
+ spec/core_ext_spec.rb
17
+ spec/import_spec.rb
18
+ spec/spec.opts
19
+ spec/spec_helper.rb
20
+ spec/table_spec.rb
21
+ tasks/docs.rake
22
+ tasks/gemspec.rake
23
+ tasks/spec.rake
24
+ terminal-table.gemspec
@@ -0,0 +1,240 @@
1
+ = Terminal Table
2
+
3
+ == Description
4
+
5
+ Terminal Table is a fast and simple, yet feature rich ASCII table generator written in Ruby.
6
+
7
+ == Installation
8
+
9
+ Install http://gemcutter.org and execute:
10
+
11
+ $ gem install terminal-table
12
+
13
+ == Usage
14
+
15
+ === Basics
16
+
17
+ To use Terminal Table:
18
+
19
+ require 'terminal-table'
20
+
21
+ To generate a table, provide an array of arrays (which are interpreted as rows):
22
+
23
+ rows = []
24
+ rows << ['One', 1]
25
+ rows << ['Two', 2]
26
+ rows << ['Three', 3]
27
+ table = Terminal::Table.new :rows => rows
28
+
29
+ # > puts table
30
+ #
31
+ # +-------+---+
32
+ # | One | 1 |
33
+ # | Two | 2 |
34
+ # | Three | 3 |
35
+ # +-------+---+
36
+
37
+
38
+ The constructor can also be given a block which is either yielded the Table object or instance evaluated:
39
+
40
+ table = Terminal::Table.new do |t|
41
+ t.rows = rows
42
+ end
43
+
44
+ table = Terminal::Table.new do
45
+ self.rows = rows
46
+ end
47
+
48
+ Adding rows one by one:
49
+
50
+ table = Terminal::Table.new do |t|
51
+ t << ['One', 1]
52
+ t.add_row ['Two', 2]
53
+ end
54
+
55
+ To add separators between rows:
56
+
57
+ table = Terminal::Table.new do |t|
58
+ t << ['One', 1]
59
+ t << :separator
60
+ t.add_row ['Two', 2]
61
+ t.add_separator
62
+ t.add_row ['Three', 3]
63
+ end
64
+
65
+ # > puts table
66
+ #
67
+ # +-------+---+
68
+ # | One | 1 |
69
+ # +-------+---+
70
+ # | Two | 2 |
71
+ # +-------+---+
72
+ # | Three | 3 |
73
+ # +-------+---+
74
+
75
+ Cells can handle multiline content:
76
+
77
+ table = Terminal::Table.new do |t|
78
+ t << ['One', 1]
79
+ t << :separator
80
+ t.add_row ["Two\nDouble", 2]
81
+ t.add_separator
82
+ t.add_row ['Three', 3]
83
+ end
84
+
85
+ # > puts table
86
+ #
87
+ # +--------+---+
88
+ # | One | 1 |
89
+ # +--------+---+
90
+ # | Two | 2 |
91
+ # | Double | |
92
+ # +--------+---+
93
+ # | Three | 3 |
94
+ # +--------+---+
95
+
96
+ === Head
97
+
98
+ To add a head to the table:
99
+
100
+ table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows
101
+
102
+ # > puts table
103
+ #
104
+ # +-------+--------+
105
+ # | Word | Number |
106
+ # +-------+--------+
107
+ # | One | 1 |
108
+ # | Two | 2 |
109
+ # | Three | 3 |
110
+ # +-------+--------+
111
+
112
+ === Title
113
+
114
+ To add a title to the table:
115
+
116
+ table = Terminal::Table.new :title => "Cheatsheet", :headings => ['Word', 'Number'], :rows => rows
117
+
118
+ # > puts table
119
+ #
120
+ # +------------+--------+
121
+ # | Cheatsheet |
122
+ # +------------+--------+
123
+ # | Word | Number |
124
+ # +------------+--------+
125
+ # | One | 1 |
126
+ # | Two | 2 |
127
+ # | Three | 3 |
128
+ # +------------+--------+
129
+
130
+ === Alignment
131
+
132
+ To align the second column to the right:
133
+
134
+ table.align_column(1, :right)
135
+
136
+ # > puts table
137
+ #
138
+ # +-------+--------+
139
+ # | Word | Number |
140
+ # +-------+--------+
141
+ # | One | 1 |
142
+ # | Two | 2 |
143
+ # | Three | 3 |
144
+ # +-------+--------+
145
+
146
+ To align an individual cell, you specify the cell value in a hash along the alignment:
147
+
148
+ table << ["Four", {:value => 4.0, :alignment => :center}]
149
+
150
+ # > puts table
151
+ #
152
+ # +-------+--------+
153
+ # | Word | Number |
154
+ # +-------+--------+
155
+ # | One | 1 |
156
+ # | Two | 2 |
157
+ # | Three | 3 |
158
+ # | Four | 4.0 |
159
+ # +-------+--------+
160
+
161
+ === Style
162
+
163
+ To specifify style options:
164
+
165
+ table = Terminal::Table.new :headings => ['Word', 'Number'], :rows => rows, :style => {:width => 80}
166
+
167
+ # > puts table
168
+ #
169
+ # +--------------------------------------+---------------------------------------+
170
+ # | Word | Number |
171
+ # +--------------------------------------+---------------------------------------+
172
+ # | One | 1 |
173
+ # | Two | 2 |
174
+ # | Three | 3 |
175
+ # +--------------------------------------+---------------------------------------+
176
+
177
+ And change styles on the fly:
178
+
179
+ table.style = {:width => 40, :padding_left => 3, :border_x => "=", :border_i => "x"}
180
+
181
+ # > puts table
182
+ #
183
+ # x====================x=================x
184
+ # | Cheatsheet |
185
+ # x====================x=================x
186
+ # | Word | Number |
187
+ # x====================x=================x
188
+ # | One | 1 |
189
+ # | Two | 2 |
190
+ # | Three | 3 |
191
+ # x====================x=================x
192
+
193
+ To change the default style options:
194
+
195
+ Terminal::Style.defaults = {:width => 80}
196
+
197
+ All Table objects created afterwards will inherit these defaults.
198
+
199
+ === Constructor options and setter methods
200
+
201
+ Valid options for the constructor are :rows, :headings, :style and :title - and all options can also be set on the created table object by their setter method:
202
+
203
+ table = Terminal::Table.new
204
+ table.title = "Cheatsheet"
205
+ table.headings = ['Word', 'Number']
206
+ table.rows = rows
207
+ table.style = {:width => 40}
208
+
209
+ == More examples
210
+
211
+ For more examples, please see the examples/examples.rb file included in the source distribution.
212
+
213
+ == Author
214
+
215
+ TJ Holowaychuk <tj@vision-media.ca>
216
+
217
+ == License
218
+
219
+ (The MIT License)
220
+
221
+ Copyright (c) 2008-2009 TJ Holowaychuk <tj@vision-media.ca>
222
+
223
+ Permission is hereby granted, free of charge, to any person obtaining
224
+ a copy of this software and associated documentation files (the
225
+ 'Software'), to deal in the Software without restriction, including
226
+ without limitation the rights to use, copy, modify, merge, publish,
227
+ distribute, sublicense, an d/or sell copies of the Software, and to
228
+ permit persons to whom the Software is furnished to do so, subject to
229
+ the following conditions:
230
+
231
+ The above copyright notice and this permission notice shall be
232
+ included in all copies or substantial portions of the Software.
233
+
234
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
235
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
236
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
237
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
238
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
239
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
240
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+ require './lib/terminal-table.rb'
6
+
7
+ Echoe.new("terminal-table", Terminal::Table::VERSION) do |p|
8
+ p.author = "TJ Holowaychuk"
9
+ p.email = "tj@vision-media.ca"
10
+ p.summary = "Simple, feature rich ascii table generation library"
11
+ p.url = "http://github.com/visionmedia/terminal-table"
12
+ p.runtime_dependencies = []
13
+ end
14
+
15
+ Dir['tasks/**/*.rake'].sort.each { |lib| load lib }
@@ -0,0 +1,14 @@
1
+
2
+ == Major:
3
+
4
+ * Nothing
5
+
6
+ == Minor:
7
+
8
+ * Programmatically add separator rows
9
+ * Add multi-column sorting
10
+ * Change; pre-create Cell and Heading objects to clean up Table a bit
11
+
12
+ == Brainstorming:
13
+
14
+ * Nothing
@@ -0,0 +1,80 @@
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
+ require 'terminal-table/import'
3
+
4
+ puts
5
+ puts table(['a', 'b'], [1, 2], [3, 4])
6
+
7
+ puts
8
+ t = table ['a', 'b']
9
+ t.style = {:padding_left => 2, :width => 80}
10
+ t << [1, 2]
11
+ t << [3, 4]
12
+ t << :separator
13
+ t << [4, 6]
14
+ puts t
15
+
16
+ puts
17
+ user_table = table do |v|
18
+ v.title = "Contact Information"
19
+ v.headings = 'First Name', 'Last Name', 'Email'
20
+ v << %w( TJ Holowaychuk tj@vision-media.ca )
21
+ v << %w( Bob Someone bob@vision-media.ca )
22
+ v << %w( Joe Whatever bob@vision-media.ca )
23
+ end
24
+ puts user_table
25
+
26
+ puts
27
+ user_table = table do |v|
28
+ v.style.width = 80
29
+ v.headings = 'First Name', 'Last Name', 'Email'
30
+ v << %w( TJ Holowaychuk tj@vision-media.ca )
31
+ v << %w( Bob Someone bob@vision-media.ca )
32
+ v << %w( Joe Whatever bob@vision-media.ca )
33
+ end
34
+ puts user_table
35
+
36
+ puts
37
+ user_table = table do
38
+ self.headings = 'First Name', 'Last Name', 'Email'
39
+ add_row ['TJ', 'Holowaychuk', 'tj@vision-media.ca']
40
+ add_row ['Bob', 'Someone', 'bob@vision-media.ca']
41
+ add_row ['Joe', 'Whatever', 'joe@vision-media.ca']
42
+ add_separator
43
+ add_row ['Total', { :value => '3', :colspan => 2, :alignment => :right }]
44
+ align_column 1, :center
45
+ end
46
+ puts user_table
47
+
48
+ puts
49
+ user_table = table do
50
+ self.headings = ['First Name', 'Last Name', {:value => 'Phones', :colspan => 2, :alignment => :center}]
51
+ add_row ['Bob', 'Someone', '123', '456']
52
+ add_row :separator
53
+ add_row ['TJ', 'Holowaychuk', {:value => "No phones\navaiable", :colspan => 2, :alignment => :center}]
54
+ add_row :separator
55
+ add_row ['Joe', 'Whatever', '4324', '343242']
56
+ end
57
+ puts user_table
58
+
59
+ rows = []
60
+ rows << ['Lines', 100]
61
+ rows << ['Comments', 20]
62
+ rows << ['Ruby', 70]
63
+ rows << ['JavaScript', 30]
64
+ puts table([nil, 'Lines'], *rows)
65
+
66
+ rows = []
67
+ rows << ['Lines', 100]
68
+ rows << ['Comments', 20]
69
+ rows << ['Ruby', 70]
70
+ rows << ['JavaScript', 30]
71
+ puts table(nil, *rows)
72
+
73
+ rows = []
74
+ rows << ['Lines', 100]
75
+ rows << ['Comments', 20]
76
+ rows << ['Ruby', 70]
77
+ rows << ['JavaScript', 30]
78
+ table = table([{ :value => 'Stats', :colspan => 2, :alignment => :center }], *rows)
79
+ table.align_column 1, :right
80
+ puts table
@@ -0,0 +1,88 @@
1
+
2
+ module Terminal
3
+ class Table
4
+ class Cell
5
+
6
+ ##
7
+ # Cell width.
8
+
9
+ attr_reader :width
10
+
11
+ ##
12
+ # Cell value.
13
+
14
+ attr_reader :value
15
+
16
+ ##
17
+ # Column span.
18
+
19
+ attr_reader :colspan
20
+
21
+ ##
22
+ # Initialize with _options_.
23
+
24
+ def initialize options = nil
25
+ @value, options = options, {} unless Hash === options
26
+ @value = options.fetch :value, value
27
+ @alignment = options.fetch :alignment, nil
28
+ @colspan = options.fetch :colspan, 1
29
+ @width = options.fetch :width, @value.to_s.size
30
+ @index = options.fetch :index
31
+ @table = options.fetch :table
32
+ end
33
+
34
+ def alignment?
35
+ !@alignment.nil?
36
+ end
37
+
38
+ def alignment
39
+ @alignment || :left
40
+ end
41
+
42
+ def alignment=(val)
43
+ supported = %w(left center right)
44
+ if supported.include?(val.to_s)
45
+ @alignment = val
46
+ else
47
+ raise "Aligment must be one of: #{supported.join(' ')}"
48
+ end
49
+ end
50
+
51
+ def lines
52
+ @value.to_s.split(/\n/)
53
+ end
54
+
55
+ ##
56
+ # Render the cell.
57
+
58
+ def render(line = 0)
59
+ left = " " * @table.style.padding_left
60
+ right = " " * @table.style.padding_right
61
+ "#{left}#{lines[line]}#{right}".align(alignment, width + @table.cell_padding)
62
+ end
63
+ alias :to_s :render
64
+
65
+ ##
66
+ # Returns the longest line in the cell and
67
+ # removes all ANSI escape sequences (e.g. color)
68
+
69
+ def value_for_column_width_recalc
70
+ str = lines.sort_by { |s| s.size }.last.to_s
71
+ str = str.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
72
+ str = str.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
73
+ str.gsub(/[\x03|\x1a]/, '')
74
+ end
75
+
76
+ ##
77
+ # Returns the width of this cell
78
+
79
+ def width
80
+ padding = (colspan - 1) * @table.cell_spacing
81
+ inner_width = (1..@colspan).to_a.inject(0) do |w, counter|
82
+ w + @table.column_width(@index + counter - 1)
83
+ end
84
+ inner_width + padding
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,8 @@
1
+
2
+ class String
3
+ def align position, length
4
+ self.__send__ position, length
5
+ end
6
+ alias_method :left, :ljust
7
+ alias_method :right, :rjust
8
+ end
@@ -0,0 +1,4 @@
1
+
2
+ require 'terminal-table'
3
+
4
+ include Terminal::Table::TableHelper
@@ -0,0 +1,48 @@
1
+ module Terminal
2
+ class Table
3
+ class Row
4
+
5
+ ##
6
+ # Row cells
7
+
8
+ attr_reader :cells
9
+
10
+ attr_reader :table
11
+
12
+ ##
13
+ # Initialize with _width_ and _options_.
14
+
15
+ def initialize table, array = []
16
+ @cell_index = 0
17
+ @table = table
18
+ @cells = []
19
+ array.each { |item| self << item }
20
+ end
21
+
22
+ def add_cell item
23
+ options = item.is_a?(Hash) ? item : {:value => item}
24
+ cell = Cell.new(options.merge(:index => @cell_index, :table => @table))
25
+ @cell_index += cell.colspan
26
+ @cells << cell
27
+ end
28
+ alias << add_cell
29
+
30
+ def [] index
31
+ cells[index]
32
+ end
33
+
34
+ def height
35
+ cells.map { |c| c.lines.count }.max
36
+ end
37
+
38
+ def render
39
+ y = @table.style.border_y
40
+ (0...height).to_a.map do |line|
41
+ y + cells.map do |cell|
42
+ cell.render(line)
43
+ end.join(y) + y
44
+ end.join("\n")
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,14 @@
1
+ module Terminal
2
+ class Table
3
+ class Separator < Row
4
+
5
+ def render
6
+ arr_x = (0...@table.number_of_columns).to_a.map do |i|
7
+ @table.style.border_x * (@table.column_width(i) + @table.cell_padding)
8
+ end
9
+ border_i = @table.style.border_i
10
+ border_i + arr_x.join(border_i) + border_i
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,61 @@
1
+
2
+ module Terminal
3
+ class Table
4
+ # A Style object holds all the formatting information for a Table object
5
+ #
6
+ # To create a table with a certain style, use either the constructor
7
+ # option <tt>:style</tt>, the Table#style object or the Table#style= method
8
+ #
9
+ # All these examples have the same effect:
10
+ #
11
+ # # by constructor
12
+ # @table = Table.new(:style => {:padding_left => 2, :width => 40})
13
+ #
14
+ # # by object
15
+ # @table.style.padding_left = 2
16
+ # @table.style.width = 40
17
+ #
18
+ # # by method
19
+ # @table.style = {:padding_left => 2, :width => 40}
20
+ #
21
+ # To set a default style for all tables created afterwards use Style.defaults=
22
+ #
23
+ # Terminal::Table::Style.defaults = {:width => 80}
24
+ #
25
+ class Style
26
+ @@defaults = {
27
+ :border_x => "-", :border_y => "|", :border_i => "+",
28
+ :padding_left => 1, :padding_right => 1,
29
+ :width => nil
30
+ }
31
+
32
+ attr_accessor :border_x
33
+ attr_accessor :border_y
34
+ attr_accessor :border_i
35
+
36
+ attr_accessor :padding_left
37
+ attr_accessor :padding_right
38
+
39
+ attr_accessor :width
40
+
41
+
42
+ def initialize options = {}
43
+ apply self.class.defaults.merge(options)
44
+ end
45
+
46
+ def apply options
47
+ options.each { |m, v| __send__ "#{m}=", v }
48
+ end
49
+
50
+ class << self
51
+ def defaults
52
+ @@defaults
53
+ end
54
+
55
+ def defaults= options
56
+ @@defaults = defaults.merge(options)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end