Class: ShoesMVC::Models::ArrayTableModel

Inherits:
TableModel
  • Object
show all
Defined in:
lib/ruby_mvc/models/array_table_model.rb

Overview

This class implements the TableModel interface based on the data being stored in an array. The elements in the array must either be a Hash, or they must respond to the

accessors for retrieving elements by key and implement

a #keys method for indicating the properties in each row instance.

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ArrayTableModel

Returns a new instance of ArrayTableModel.



37
38
39
# File 'lib/ruby_mvc/models/array_table_model.rb', line 37

def initialize(data)
  @data = data
end

Instance Method Details

#each(&block) ⇒ Object



49
50
51
# File 'lib/ruby_mvc/models/array_table_model.rb', line 49

def each(&block)
  @data.each(&block)
end

#each_with_index(&block) ⇒ Object



53
54
55
# File 'lib/ruby_mvc/models/array_table_model.rb', line 53

def each_with_index(&block)
  @data.each_with_index(&block)
end

#keysObject



41
42
43
44
45
46
47
# File 'lib/ruby_mvc/models/array_table_model.rb', line 41

def keys
  if @data && @data.size > 0
    @data.keys
  else
    {}
  end
end