Class: Toquen::DetailsTable
- Inherits:
-
Object
- Object
- Toquen::DetailsTable
- Defined in:
- lib/toquen/details_table.rb
Instance Method Summary collapse
-
#initialize(instances, region) ⇒ DetailsTable
constructor
A new instance of DetailsTable.
- #instance_to_row(instance) ⇒ Object
- #output ⇒ Object
Constructor Details
#initialize(instances, region) ⇒ DetailsTable
Returns a new instance of DetailsTable.
7 8 9 10 11 |
# File 'lib/toquen/details_table.rb', line 7 def initialize(instances, region) @instances = instances @region = region @color = Term::ANSIColor end |
Instance Method Details
#instance_to_row(instance) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/toquen/details_table.rb', line 30 def instance_to_row(instance) [ @color.green { instance[:name] }, @color.yellow { instance[:roles].join(",") }, @color.magenta { instance[:environment] || "" }, instance[:external_dns].nil? ? "(N/A)" : @color.cyan(instance[:external_dns]) + " (#{instance[:external_ip]})", instance[:internal_dns].nil? ? "(N/A)" : @color.cyan(instance[:internal_dns]) + " (#{instance[:internal_ip]})", @color.red { instance[:type] } ] end |
#output ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/toquen/details_table.rb', line 13 def output table = Terminal::Table.new( :style => { :border_x => "", :border_i => "", :border_y => "" } ) table.title = @color.bold { "Instances in #{@region}" } header = [ "Name", "Roles", "Env", "Public", "Private", "Type" ] table.add_row header.map { |h| @color.underline @color.bold h } @instances.each do |instance| table.add_row instance_to_row(instance) end puts table.to_s end |