Class: View

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

Instance Method Summary collapse

Constructor Details

#initialize(name, items, keys) ⇒ View

Returns a new instance of View.



15
16
17
18
19
# File 'lib/dew/view.rb', line 15

def initialize(name, items, keys)
  @name = name
  @items = items
  @keys = keys
end

Instance Method Details

#indexObject



21
22
23
24
# File 'lib/dew/view.rb', line 21

def index
  rows = @items.collect { |item| collect_values(item) }
  "#{@name}:\n#{rows.empty? ? "None\n".indent(2) : table(@keys, *rows).to_s.indent(2)}"
end

#show(i) ⇒ Object



26
27
28
29
# File 'lib/dew/view.rb', line 26

def show(i)
  "#{@name}:\n" +
  table(nil, *@keys.collect { |item| item }.zip( collect_values(@items[i]))).to_s.indent(2)
end