Skip to content

Instantly share code, notes, and snippets.

@kshahkshah
Last active October 11, 2016 18:29
Show Gist options
  • Save kshahkshah/6c4abac081f29476a04f68f06f9cfceb to your computer and use it in GitHub Desktop.
Save kshahkshah/6c4abac081f29476a04f68f06f9cfceb to your computer and use it in GitHub Desktop.
#file_path = some excelx file with 6 sheets.....
## WITH DUP
roo = Roo::Spreadsheet.open file_path
jobs = Concurrent::Array.new
roo.each_with_pagename do |name, sheet|
local_sheet = sheet.dup
jobs << Concurrent.future {
local_sheet.last_row
}
end
puts Concurrent.zip(*jobs).value
# 25
# 22
# 22
# 22
# 22
# 5228
## WITHOUT DUP (DOESNT WORK)
roo = Roo::Spreadsheet.open file_path
jobs = Concurrent::Array.new
roo.each_with_pagename do |name, sheet|
local_sheet = sheet.dup
jobs << Concurrent.future {
local_sheet.last_row
}
end
puts Concurrent.zip(*jobs).value
# 25
# 5228
# 5228
# 5228
# 5228
# 5228
### ALTERNATE METHOD by calling a method (works)
def get_sheet(s,n)
s.default_sheet=n
s
end
spreadsheet = Roo::Spreadsheet.open file_path
jobs = Concurrent::Array.new
roo.sheets.each do |sheet_name|
jobs << Concurrent.future {
get_sheet(spreadsheet, sheet_name).last_row
}
end
puts Concurrent.zip(*jobs).value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment