Class: Xsv::StylesHandler
Overview
StylesHandler interprets the relevant parts of styles.xml This is used internally when opening a sheet.
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(num_fmts, &block) ⇒ StylesHandler
Returns a new instance of StylesHandler.
18
19
20
21
22
23
|
# File 'lib/xsv/styles_handler.rb', line 18
def initialize(num_fmts, &block)
@block = block
@state = nil
@xfs = []
@num_fmts = num_fmts
end
|
Class Method Details
.get_styles(io) ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/xsv/styles_handler.rb', line 7
def self.get_styles(io)
handler = new(Xsv::Helpers::BUILT_IN_NUMBER_FORMATS.dup) do |xfs, num_fmts|
@xfs = xfs
@num_fmts = num_fmts
end
handler.parse(io)
[@xfs, @num_fmts]
end
|
Instance Method Details
#end_element(name) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/xsv/styles_handler.rb', line 36
def end_element(name)
case name
when "styleSheet"
@block.call(@xfs, @num_fmts)
when "cellXfs"
@state = nil
end
end
|
#start_element(name, attrs) ⇒ Object
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/xsv/styles_handler.rb', line 25
def start_element(name, attrs)
case name
when "cellXfs"
@state = "cellXfs"
when "xf"
@xfs << attrs.transform_values(&:to_i) if @state == "cellXfs"
when "numFmt"
@num_fmts[attrs[:numFmtId].to_i] = attrs[:formatCode]
end
end
|