Class: Roo::Base

Inherits:
Object show all
Defined in:
lib/libis/tools/extend/roo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#partial_matchObject

changes:

  • added option :partial_match to allow to use headers that only partially match the query

  • added option :required_headers to force the result to have at least these columns

  • allow option :headers to contain an array with header labels that will be forced when no header row is found

  • improved proper range scanning (first_row->last_row and first_column->last_column)



16
17
18
# File 'lib/libis/tools/extend/roo.rb', line 16

def partial_match
  @partial_match
end

Instance Method Details

#each(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/libis/tools/extend/roo.rb', line 18

def each(options = {})
  return to_enum(:each, options) unless block_given?

  @partial_match = options.delete(:partial_match) if options.has_key?(:partial_match)
  required_headers = options.delete(:required_headers) if options.has_key?(:required_headers)

  if options.empty?
    first_row.upto(last_row) do |line|
      yield row(line)
    end
  else
    clean_sheet_if_need(options)
    @headers = search_or_set_header(options)
    if required_headers
      raise Roo::HeaderRowIncompleteError unless headers.keys & required_headers == required_headers
    end

    header_line.upto(last_row) do |line|
      yield(headers.each_with_object({}) { |(k, v), hash| hash[k] = cell(line, v) })
    end
  end
end