Class: Saxlsx::SheetCollectionParser

Inherits:
Ox::Sax
  • Object
show all
Defined in:
lib/saxlsx/sheet_collection_parser.rb

Defined Under Namespace

Classes: CurrentSheet

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_system, workbook, &block) ⇒ SheetCollectionParser

Returns a new instance of SheetCollectionParser.



14
15
16
17
18
19
20
# File 'lib/saxlsx/sheet_collection_parser.rb', line 14

def initialize(file_system, workbook, &block)
  @file_system = file_system
  @workbook = workbook
  @block = block
  @index = -1
  @workbook_pr = false
end

Class Method Details

.parse(file_system, workbook, &block) ⇒ Object



7
8
9
10
11
12
# File 'lib/saxlsx/sheet_collection_parser.rb', line 7

def self.parse(file_system, workbook, &block)
  SaxParser.parse(
    self.new(file_system, workbook, &block),
    file_system.workbook
  )
end

Instance Method Details

#attr(name, value) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/saxlsx/sheet_collection_parser.rb', line 46

def attr(name, value)
  if @current_sheet
    if name == :name
      @current_sheet.name = value
    end
  elsif @workbook_pr
    if name == :date1904 && value =~ /true|1/i
      @workbook.date1904 = true
    end
  end
end

#end_element(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/saxlsx/sheet_collection_parser.rb', line 31

def end_element(name)
  case name
  when :sheet
    @block.call Sheet.new(
      @current_sheet.name,
      @current_sheet.index,
      @file_system,
      @workbook
    )
    @current_sheet = nil
  when :workbookPr
    @workbook_pr = false
  end
end

#start_element(name) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/saxlsx/sheet_collection_parser.rb', line 22

def start_element(name)
  case name
  when :sheet
    @current_sheet = CurrentSheet.new(@index += 1)
  when :workbookPr
    @workbook_pr = true
  end
end