Created
October 11, 2013 14:40
-
-
Save ashmoran/6935831 to your computer and use it in GitHub Desktop.
Hideous first iteration of an algorithm I wrote
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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