Class: KXI::CLI::PropertyList
- Inherits:
-
Object
- Object
- KXI::CLI::PropertyList
- Defined in:
- lib/kxi/cli/property_list.rb
Overview
Property list renderer
Instance Method Summary collapse
-
#field(name, value) ⇒ Object
Sets a property.
-
#initialize ⇒ PropertyList
constructor
Instantiates the PropertyList class.
-
#render(cols = 4) ⇒ Object
Renders the property list into stdout.
Constructor Details
#initialize ⇒ PropertyList
Instantiates the KXI::CLI::PropertyList class
8 9 10 11 |
# File 'lib/kxi/cli/property_list.rb', line 8 def initialize @align = 0 @data = {} end |
Instance Method Details
#field(name, value) ⇒ Object
Sets a property
16 17 18 19 |
# File 'lib/kxi/cli/property_list.rb', line 16 def field(name, value) @data[name] = value @align = name.length if name.length > @align end |
#render(cols = 4) ⇒ Object
Renders the property list into stdout
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/kxi/cli/property_list.rb', line 23 def render(cols = 4) @data.each_pair do |k, v| if v.kind_of?(Array) print("#{pad(k)}: ") v.each_index do |idx| if idx > 0 and idx % cols == 0 puts('') print(' ' * (@align + 2)) elsif idx > 0 print(', ') end print(v[idx]) end puts('') else puts("#{pad(k)}: #{v}") end end end |