class ProMotion::TableData

Attributes

data[RW]
filtered_data[RW]
table_view[RW]

Public Class Methods

new(data, table_view, search_action = nil) click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 8
def initialize(data, table_view, search_action = nil)
  @search_action ||= search_action

  if data.include?(nil)
    mp("Warning: You have a `nil` section in your table_data method.", force_color: :yellow)
  end

  self.data = data.compact.each_with_index.map do |section,index|
    if section[:cells].include?(nil)
      mp("Warning: You have a `nil` cell in table section #{index}.", force_color: :yellow)
      section[:cells].compact!
    end
    section
  end
  self.table_view = WeakRef.new(table_view)
end

Public Instance Methods

cell(params={}) click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 37
def cell(params={})
  params = index_path_to_section_index(params)
  table_section = params[:unfiltered] ? self.data[params[:section]] : self.section(params[:section])
  c = table_section[:cells].at(params[:index].to_i)
  set_data_cell_defaults(c)
end
clear_filter() click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 91
def clear_filter
  @filtered = false
end
delete_cell(params={}) click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 44
def delete_cell(params={})
  params = index_path_to_section_index(params)
  table_section = self.section(params[:section])
  table_section[:cells].delete_at(params[:index].to_i)
end
filtered?() click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 58
def filtered?
  @filtered == true
end
move_cell(from, to) click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 50
def move_cell(from, to)
  section(to.section)[:cells].insert(to.row, section(from.section)[:cells].delete_at(from.row))
end
search_string() click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 62
def search_string
  @search_string ||= nil
end
section(index) click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 25
def section(index)
  sections.at(index) || { cells: [] }
end
section_length(index) click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 33
def section_length(index)
  section(index)[:cells].length
end
sections() click to toggle source
# File lib/ProMotion/table/data/table_data.rb, line 29
def sections
  filtered? ? self.filtered_data : self.data
end