@@ -288,12 +288,12 @@ def each(options = {})
288
288
clean_sheet_if_need ( options )
289
289
search_or_set_header ( options )
290
290
headers = @headers ||
291
- Hash [ ( first_column ..last_column ) . map do |col |
292
- [ cell ( @header_line , col ) , col ]
293
- end ]
291
+ ( first_column ..last_column ) . each_with_object ( { } ) do |col , hash |
292
+ hash [ cell ( @header_line , col ) ] = col
293
+ end
294
294
295
295
@header_line . upto ( last_row ) do |line |
296
- yield ( Hash [ headers . map { |k , v | [ k , cell ( line , v ) ] } ] )
296
+ yield ( headers . each_with_object ( { } ) { |( k , v ) , hash | hash [ k ] = cell ( line , v ) } )
297
297
end
298
298
end
299
299
end
@@ -424,9 +424,9 @@ def find_by_row(row_index)
424
424
425
425
def find_by_conditions ( options )
426
426
rows = first_row . upto ( last_row )
427
- header_for = Hash [ 1 . upto ( last_column ) . map do |col |
428
- [ col , cell ( @header_line , col ) ]
429
- end ]
427
+ header_for = 1 . upto ( last_column ) . each_with_object ( { } ) do |col , hash |
428
+ hash [ col ] = cell ( @header_line , col )
429
+ end
430
430
431
431
# are all conditions met?
432
432
conditions = options [ :conditions ]
@@ -441,9 +441,9 @@ def find_by_conditions(options)
441
441
rows . map { |i | row ( i ) }
442
442
else
443
443
rows . map do |i |
444
- Hash [ 1 . upto ( row ( i ) . size ) . map do |j |
445
- [ header_for . fetch ( j ) , cell ( i , j ) ]
446
- end ]
444
+ 1 . upto ( row ( i ) . size ) . each_with_object ( { } ) do |j , hash |
445
+ hash [ header_for . fetch ( j ) ] = cell ( i , j )
446
+ end
447
447
end
448
448
end
449
449
end
@@ -497,8 +497,11 @@ def sanitize_value(v)
497
497
def set_headers ( hash = { } )
498
498
# try to find header row with all values or give an error
499
499
# then create new hash by indexing strings and keeping integers for header array
500
- @headers = row_with ( hash . values , true )
501
- @headers = Hash [ hash . keys . zip ( @headers . map { |x | header_index ( x ) } ) ]
500
+ header_row = row_with ( hash . values , true )
501
+ @headers = { }
502
+ hash . each_with_index do |( key , _ ) , index |
503
+ @headers [ key ] = header_index ( header_row [ index ] )
504
+ end
502
505
end
503
506
504
507
def header_index ( query )
0 commit comments