Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created October 11, 2013 14:40
Show Gist options
  • Save ashmoran/6935831 to your computer and use it in GitHub Desktop.
Save ashmoran/6935831 to your computer and use it in GitHub Desktop.
Hideous first iteration of an algorithm I wrote
def header_rows(labeller = Labeller.new)
# This won't handle mismatched sizes yet
# Also hack the null case for now
number_of_rows = @fragments.map(&:number_of_dimensions).max || 0
bottom_up_header_rows = [ ]
number_of_rows.times do |row_index|
current_row = bottom_up_header_rows[row_index] = [ ]
@fragments.each do |fragment|
if fragment.number_of_dimensions <= row_index
current_row << HeaderColumn.new
else
index_from_end = -(row_index + 1)
columns_for_row = fragment.dimension_value_labels[index_from_end].map { |label|
HeaderColumn.new(
label: labeller.label_for(label),
number_of_encompassed_dimension_values: fragment.number_of_encompassed_dimension_values_at_level(index_from_end)
)
}
current_row.concat(columns_for_row)
end
end
end
bottom_up_header_rows.reverse
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment