Class: RubyMVC::Models::KeyedArrayTableModel

Inherits:
TableModel show all
Defined in:
lib/ruby_mvc/models/keyed_array_table_model.rb

Defined Under Namespace

Classes: Row

Instance Method Summary collapse

Methods inherited from TableModel

#[], #create_rows, #insert_row, #insert_rows, #remove_row, #remove_rows, #update_row, #value_for

Methods inherited from Model

#[], #[]=, adapt, #each_label, #is_editable?, #label_for, #labels, #link_labels, #size

Methods included from Toolkit::SignalHandler::ClassMethods

#signal, #signals, #valid_signal!, #valid_signal?

Methods included from Toolkit::SignalHandler

#signal_connect, #signal_disconnect, #signal_emit

Constructor Details

#initialize(keys, data) ⇒ KeyedArrayTableModel

This method is used to initialize the mo



59
60
61
62
63
# File 'lib/ruby_mvc/models/keyed_array_table_model.rb', line 59

def initialize(keys, data)
  @keys = {}
  keys.each_with_index { |x, i| @keys[x.to_sym] = i }
  @data = data
end

Instance Method Details

#each(&block) ⇒ Object



69
70
71
72
73
# File 'lib/ruby_mvc/models/keyed_array_table_model.rb', line 69

def each(&block)
  @data.each do |x|
    block.call(Row.new(@keys, x))
  end
end

#each_with_index(&block) ⇒ Object



75
76
77
78
79
# File 'lib/ruby_mvc/models/keyed_array_table_model.rb', line 75

def each_with_index(&block)
  @data.each_with_index do |x, i|
    block.call(Row.new(@keys, x), i)
  end
end

#keysObject



65
66
67
# File 'lib/ruby_mvc/models/keyed_array_table_model.rb', line 65

def keys
  @keys.keys
end