Class: Flucti::Utilities::ListDisplayer
- Inherits:
-
Object
- Object
- Flucti::Utilities::ListDisplayer
- Defined in:
- lib/flucti/utilities/list_displayer.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #display(entries) ⇒ Object
- #display_single_entry(entry) ⇒ Object
-
#initialize(options = {}, &block) ⇒ ListDisplayer
constructor
A new instance of ListDisplayer.
Constructor Details
#initialize(options = {}, &block) ⇒ ListDisplayer
Returns a new instance of ListDisplayer.
6 7 8 9 |
# File 'lib/flucti/utilities/list_displayer.rb', line 6 def initialize(={}, &block) @options = @columns = build_column_list(&block) end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/flucti/utilities/list_displayer.rb', line 4 def columns @columns end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/flucti/utilities/list_displayer.rb', line 4 def @options end |
Instance Method Details
#display(entries) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/flucti/utilities/list_displayer.rb', line 11 def display(entries) if [:table] || entries.size > 3 puts entries.inject(Utilities::Table.new(*columns.map { |title,| title })) { |table, entry| table << columns.map { |title, proc| proc.call(entry) } } else entries.each do |entry| if attribute = [:title] puts_subtitle(entry.send(attribute)) else title, proc = columns.first val = proc.call(entry) puts_subtitle(val.to_s =~ /^\d+$/ ? "#{title}=#{val}" : val) end display_single_entry(entry) end end puts "\nTotal: #{entries.size}" end |
#display_single_entry(entry) ⇒ Object
31 32 33 34 35 |
# File 'lib/flucti/utilities/list_displayer.rb', line 31 def display_single_entry(entry) columns.each do |title, proc| puts "%-*s %s" % [column_width+1, "#{title}:", proc.call(entry)] end end |