Class: ExcelXml::Worksheet::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/excelxml/worksheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worksheet) ⇒ Parser

Returns a new instance of Parser.



39
40
41
# File 'lib/excelxml/worksheet.rb', line 39

def initialize worksheet
  @worksheet = worksheet
end

Instance Attribute Details

#header_row_indexObject

Returns the value of attribute header_row_index.



37
38
39
# File 'lib/excelxml/worksheet.rb', line 37

def header_row_index
  @header_row_index
end

#worksheetObject (readonly)

Returns the value of attribute worksheet.



36
37
38
# File 'lib/excelxml/worksheet.rb', line 36

def worksheet
  @worksheet
end

Instance Method Details

#has_header?(header) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/excelxml/worksheet.rb', line 51

def has_header? header
  index_to_header_map.find {|e| e.match header }
end

#index_to_header_mapObject



55
56
57
# File 'lib/excelxml/worksheet.rb', line 55

def index_to_header_map
  @index_to_header_map ||= @worksheet.rows[header_row_index].collect {|h| h ? h.strip : nil }
end

#is_header?(row_number, fields) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/excelxml/worksheet.rb', line 67

def is_header? row_number, fields
  return true if mandatory_columns.all? {|mc| fields.compact.any? {|f| f.match mc } }
  return false
end

#mandatory_columnsObject

Override methods



63
64
65
# File 'lib/excelxml/worksheet.rb', line 63

def mandatory_columns
  []
end

#rowsObject



43
44
45
46
47
48
49
# File 'lib/excelxml/worksheet.rb', line 43

def rows
  @rows ||= begin
    @worksheet.rows[(header_row_index+1)..-1].collect do |fields|
      Fields.new(self, fields)
    end
  end
end