Method: Statsample::Codification.excel_to_recoded_hash

Defined in:
lib/statsample/codification.rb

.excel_to_recoded_hash(filename) ⇒ Object

From a excel generates a dictionary hash to use on recode_dataset_simple!() or recode_dataset_split!().


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/statsample/codification.rb', line 97

def excel_to_recoded_hash(filename)
  require 'spreadsheet'
  h={}
  book = Spreadsheet.open filename
  sheet= book.worksheet 0
  row_i=0
  sheet.each do |row|
    row_i += 1
    next if row_i == 1 or row[0].nil? or row[1].nil? or row[2].nil?
    key = row[0].to_sym
    h[key] ||= {}
    h[key][row[1]] = row[2]
  end
  h
end