lib/worksheet.rb in rxl-0.1.1 vs lib/worksheet.rb in rxl-0.1.2
- old
+ new
@@ -8,12 +8,12 @@
########################################################
### GET HASH WORKSHEET FROM RUBYXL WORKSHEET ###
########################################################
def self.rubyxl_to_hash(rubyxl_worksheet)
- rubyxl_rows = rubyxl_worksheet.each_with_index.map do |rubyxl_row, rubyxl_row_index|
- { rubyxl_row: rubyxl_row, rubyxl_row_index: rubyxl_row_index }
+ rubyxl_rows = rubyxl_worksheet.map do |rubyxl_row|
+ { rubyxl_row: rubyxl_row, rubyxl_row_index: rubyxl_row ? rubyxl_row.r - 1 : nil }
end
hash_worksheet = Cells.rubyxl_to_hash(rubyxl_rows)
process_sheet_to_populated_block(hash_worksheet)
Mitrush.delete_keys(hash_worksheet, %i[row_count column_count])
hash_worksheet
@@ -69,14 +69,15 @@
hash_worksheet[key] = {} unless hash_worksheet.has_key?(key)
end
end
def self.hash_worksheet_to_hash_table(raw_hash)
- cells = raw_hash[:cells]
+ cells = Mitrush.deep_copy(raw_hash)
columns = cells.keys.map { |key| key[/\D+/] }.uniq
- cells.keys.map { |key| key[/\d+/] }.uniq[1..-1].map do |row_number|
- columns.each_with_object({}) do |column_letter, this_hash|
- this_hash[cells["#{column_letter}1"][:value]] = cells["#{column_letter}#{row_number}"][:value]
+ row_nums = cells.keys.map { |key| key[/\d+/] }.uniq[1..-1].sort
+ row_nums.map do |row_number|
+ columns.each_with_object({}) do |column_letter, h|
+ h[cells["#{column_letter}1"][:value]] = cells["#{column_letter}#{row_number}"][:value]
end
end
end
def self.validate_hash_worksheet(hash_worksheet_name, hash_worksheet)
\ No newline at end of file