Class: FormattedStdout

Inherits:
Object
  • Object
show all
Defined in:
lib/stdout.rb

Overview

Copyright 2011 Ryan J. Geyer

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column_width = 0) ⇒ FormattedStdout

Returns a new instance of FormattedStdout.



17
18
19
# File 'lib/stdout.rb', line 17

def initialize(column_width = 0)
  @column_width = column_width
end

Instance Attribute Details

#column_widthObject

Returns the value of attribute column_width.



15
16
17
# File 'lib/stdout.rb', line 15

def column_width
  @column_width
end

Instance Method Details

#put_columns(col_hash_ary) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stdout.rb', line 21

def put_columns(col_hash_ary)
  outval = ''
  col_hash_ary.each do |column|
    if column.include?(:ansi_codes)
      outval += "\e["
      outval += column[:ansi_codes].join(';')
      outval += "m"
      outval += "#{column[:value].ljust(@column_width)}\e[0m"
    else
      outval += "#{column[:value].ljust(@column_width)}"
    end
  end
  puts outval
end