Skip to content

Commit

Permalink
Make calculate_column_widths a little less eyeblood inducing
Browse files Browse the repository at this point in the history
  • Loading branch information
practicingruby committed Apr 24, 2009
1 parent 456deaf commit 42bba18
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/prawn/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def default_configuration
def calculate_column_widths(manual_widths=nil, width=nil)
@column_widths = [0] * @data[0].inject(0){ |acc, e|
acc += (e.is_a?(Hash) && e.has_key?(:colspan)) ? e[:colspan] : 1 }

renderable_data.each do |row|
colspan = 0
row.each_with_index do |cell,i|
Expand All @@ -206,6 +207,10 @@ def calculate_column_widths(manual_widths=nil, width=nil)
end
end

fit_within_bounds(manual_widths, width)
end

def fit_within_bounds(manual_widths, width)
manual_width = 0
manual_widths.each { |k,v|
@column_widths[k] = v; manual_width += v } if manual_widths
Expand Down Expand Up @@ -234,6 +239,7 @@ def calculate_column_widths(manual_widths=nil, width=nil)
end
end


def renderable_data
C(:headers) ? [C(:headers)] + @data : @data
end
Expand Down

0 comments on commit 42bba18

Please sign in to comment.