Class: VagrantPlugininspection::UI::Columnized::Layout
- Inherits:
-
Object
- Object
- VagrantPlugininspection::UI::Columnized::Layout
- Defined in:
- lib/vagrant-plugins/ui.rb
Constant Summary collapse
- BOOL_MAP =
{ true => '*', false => '', nil => '' }
Instance Method Summary collapse
-
#column(key, opts = nil) ⇒ Object
Adds a column definition to the current position.
-
#initialize(simple = nil) ⇒ Layout
constructor
A new instance of Layout.
-
#rows(data, opts = nil) ⇒ Array
Returns an Array of columns formatted lines.
-
#seperator(str) ⇒ Object
Adds a seperator to the current position.
Constructor Details
#initialize(simple = nil) ⇒ Layout
Returns a new instance of Layout.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/vagrant-plugins/ui.rb', line 16 def initialize(simple=nil) simple.each { |column| self.column(column) self.seperator("\t") } if simple @heads = Hash.new @columns = Hash.new @stack = Array.new end |
Instance Method Details
#column(key, opts = nil) ⇒ Object
Adds a column definition to the current position
28 29 30 31 32 33 34 35 |
# File 'lib/vagrant-plugins/ui.rb', line 28 def column(key, opts=nil) defaults = { :name => key.to_s } opts = defaults.merge(opts || {}) @heads[key] = opts[:name] @columns[key] = opts @stack << key end |
#rows(data, opts = nil) ⇒ Array
Returns an Array of columns formatted lines. Also includes column headers and horizonal header line.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vagrant-plugins/ui.rb', line 45 def rows(data, opts=nil) defaults = { :heads => true } opts = defaults.merge(opts || {}) data = clean(data) size = sizes(data) rendered = Array.new if opts.delete(:heads) rendered << columnize_row(@heads, size) rendered << horizontal_line(size) end rendered << data.map { |line| columnize_row(line, size) } # return a flat Array with lines rendered.flatten end |
#seperator(str) ⇒ Object
Adds a seperator to the current position
38 39 40 |
# File 'lib/vagrant-plugins/ui.rb', line 38 def seperator(str) @stack << str.to_s end |