From c04f25cf0c8eed75a5029932c94aeec303178247 Mon Sep 17 00:00:00 2001 From: Ryan Linton Date: Fri, 22 Aug 2014 12:24:48 -0700 Subject: [PATCH] Attempt to improve Code Climate score --- lib/ProMotion/table/data/table_data.rb | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/ProMotion/table/data/table_data.rb b/lib/ProMotion/table/data/table_data.rb index d490662..c77faaf 100644 --- a/lib/ProMotion/table/data/table_data.rb +++ b/lib/ProMotion/table/data/table_data.rb @@ -21,23 +21,13 @@ module ProMotion end def cell(params={}) - if params[:index_path] - params[:section] = params[:index_path].section - params[:index] = params[:index_path].row - end - - table_section = self.section(params[:section]) + table_section = set_table_section(params) c = table_section[:cells].at(params[:index].to_i) set_data_cell_defaults c end def delete_cell(params={}) - if params[:index_path] - params[:section] = params[:index_path].section - params[:index] = params[:index_path].row - end - - table_section = self.section(params[:section]) + table_section = set_table_section(params) table_section[:cells].delete_at(params[:index].to_i) end @@ -49,8 +39,7 @@ module ProMotion self.search_string = search_string.downcase.strip self.data.compact.each do |section| - new_section = {} - new_section[:cells] = [] + new_section = { cells: [] } new_section[:cells] = section[:cells].map do |cell| cell[:searchable] != false && "#{cell[:title]}\n#{cell[:search_text]}".downcase.strip.include?(self.search_string) ? cell : nil @@ -99,5 +88,13 @@ module ProMotion ident end + def set_table_section(params={}) + if params[:index_path] + params[:section] = params[:index_path].section + params[:index] = params[:index_path].row + end + + self.section(params[:section]) + end end end