Class: Decisive::XLSHasher

Inherits:
Struct
  • Object
show all
Defined in:
lib/decisive/xls_hasher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



4
5
6
# File 'lib/decisive/xls_hasher.rb', line 4

def path
  @path
end

Instance Method Details

#to_hashObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/decisive/xls_hasher.rb', line 5

def to_hash
  spreadsheet = RubyXL::Parser.parse(path)
  spreadsheet.worksheets.reduce({}) do |hash, worksheet|
    actual = []
    worksheet.each do |row|
      cells = row.cells.map do |cell|
        if cell.formula
          "=" + cell.formula.expression
        else
          cell.value
        end
      end
      actual << cells
    end
    hash.merge worksheet.sheet_name => actual
  end
end