Class: Condition::Reader::RooReader

Inherits:
Object
  • Object
show all
Defined in:
lib/condition/reader/roo_reader.rb

Instance Method Summary collapse

Instance Method Details

#read(ss) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/condition/reader/roo_reader.rb', line 13

def read(ss)
  row_index = 1
  res = []
  while true
    break if nil == ss.cell(row_index, 1)
    table = []
    while true
      row = read_row(ss, row_index)
      row_index += 1
      break if 0 == row.size
      table << row
    end
    res << table
  end
  res
end

#read_row(ss, row_index) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/condition/reader/roo_reader.rb', line 30

def read_row(ss, row_index)
  column_index = 1
  result = []
  while true
    value = ss.cell(row_index, column_index)
    return result if nil == value
    result << value
    column_index += 1
  end
end

#read_sheet(path, sheet_index) ⇒ Object



7
8
9
10
11
# File 'lib/condition/reader/roo_reader.rb', line 7

def read_sheet(path, sheet_index)
  ss =  Roo::Spreadsheet.open(path)
  ss.default_sheet = ss.sheets[sheet_index]
  read(ss)
end