Class: Bean::TableDataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/bean/table_data_source.rb

Overview

A simple table data source. Provided an array it will handle the needed calbacks for the table.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Bean::TableDataSource

Create the table data source

The elements of the provided data source either need to respond to [] and provide each of the needed keys or, need to respond to methods based on the key names.

Parameters:

  • data (Array)

    The data to be provided to the table



17
18
19
# File 'lib/bean/table_data_source.rb', line 17

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

The data to provide to the table



6
7
8
# File 'lib/bean/table_data_source.rb', line 6

def data
  @data
end

Instance Method Details

#numberOfRowsInTableView(table) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the number of rows in the table



24
25
26
# File 'lib/bean/table_data_source.rb', line 24

def numberOfRowsInTableView(table)
  data.length
end

#tableView(table, sortDescriptorsDidChange: old_descriptors) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sorts the data based on the current table sort descriptors



31
32
33
34
35
36
37
38
39
# File 'lib/bean/table_data_source.rb', line 31

def tableView(table, objectValueForTableColumn:column, row:i)
  ident = column.identifier

  if data[i].respond_to?(:[])
    data[i][ident.intern]
  elsif data[i].respond_to?(ident.to_sym)
    data[i].send(ident.to_sym)
  end
end