lib/roo/generic_spreadsheet.rb in roo-0.8.0 vs lib/roo/generic_spreadsheet.rb in roo-0.8.1

- old
+ new

@@ -66,17 +66,28 @@ sheets.each {|sheet| # $log.debug("Info fuer Sheet=#{sheet}") self.default_sheet = sheet # $log.debug("nach default_sheet=") result << "Sheet " + n.to_s + ":\n" - result << " First row: #{first_row}\n" + if !(first_row) # && last_row && first_column) # && last_column) + result << " - empty -" + end + if first_row + result << " First row: #{first_row}\n" + end # $log.debug("nach first_row") - result << " Last row: #{last_row}\n" + if last_row + result << " Last row: #{last_row}\n" + end # $log.debug("nach last_row") - result << " First column: #{GenericSpreadsheet.number_to_letter(first_column)}\n" + if first_column + result << " First column: #{GenericSpreadsheet.number_to_letter(first_column)}\n" + end # $log.debug("nach first_column") - result << " Last column: #{GenericSpreadsheet.number_to_letter(last_column)}" + if last_column + result << " Last column: #{GenericSpreadsheet.number_to_letter(last_column)}" + end # $log.debug("nach last_column") result << "\n" if sheet != sheets.last n += 1 } # $log.debug(self.class.to_s+"#info ended") @@ -139,11 +150,11 @@ File.join(@tmpdir, File.basename(uri)) end # returns the number of the last non-empty row def last_row(sheet=nil) - sheet = @default_sheet unless sheet + sheet = @default_sheet unless sheet read_cells(sheet) unless @cells_read[sheet] if @last_row[sheet] return @last_row[sheet] end impossible_value = 0 @@ -151,11 +162,11 @@ @cell[sheet].each_pair {|key,value| y,x = key.split(',') y = y.to_i result = [result, y].max if value } - result = nil if result == impossible_value + result = nil if result == impossible_value @last_row[sheet] = result result end # returns the number of the last non-empty column @@ -188,11 +199,11 @@ read_cells(sheet) unless @cells_read[sheet] if @first_row[sheet] return @first_row[sheet] end impossible_value = 999_999 # more than a spreadsheet can hold - result = impossible_value + result = impossible_value @cell[sheet].each_pair {|key,value| y,x = key.split(',') y = y.to_i result = [result, y].min if value } @@ -209,21 +220,21 @@ read_cells(sheet) unless @cells_read[sheet] if @first_column[sheet] return @first_column[sheet] end impossible_value = 999_999 # more than a spreadsheet can hold - result = impossible_value + result = impossible_value @cell[sheet].each_pair {|key,value| y,x = key.split(',') x = x.to_i result = [result, x].min if value } result = nil if result == impossible_value @first_column[sheet] = result result end - + # convert a number to something like this: 'AB' def GenericSpreadsheet.number_to_letter(n) letters="" while n > 0 num = n%26 @@ -259,18 +270,18 @@ # helper method def after(d) if DateTime.now > d yield - end - end + end + end # helper method def before(d) - if DateTime.now <= d + if DateTime.now <= d yield - end - end + end + end private def initialize