Class: Xsv::SheetsIdsHandler

Inherits:
SaxParser show all
Defined in:
lib/xsv/sheets_ids_handler.rb

Overview

SheetsIdsHandler interprets the relevant parts of workbook.xml This is used internally to get the sheets ids, relationship_ids, and names when opening a workbook.

Constant Summary

Constants inherited from SaxParser

Xsv::SaxParser::ATTR_REGEX

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SaxParser

#parse

Constructor Details

#initialize(&block) ⇒ SheetsIdsHandler

Returns a new instance of SheetsIdsHandler.



17
18
19
# File 'lib/xsv/sheets_ids_handler.rb', line 17

def initialize(&block)
  @block = block
end

Class Method Details

.get_sheets_ids(io) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/xsv/sheets_ids_handler.rb', line 7

def self.get_sheets_ids(io)
  sheets_ids = []

  new { |sheet_ids| sheets_ids << sheet_ids }.parse(io)

  sheets_ids.each do |sheet|
    sheet[:name].force_encoding(Encoding::UTF_8)
  end
end

Instance Method Details

#start_element(name, attrs) ⇒ Object



21
22
23
# File 'lib/xsv/sheets_ids_handler.rb', line 21

def start_element(name, attrs)
  @block.call(attrs.slice(:name, :sheetId, :state, :id)) if name == "sheet"
end