Class: ExcelXml::Workbook::Parser
- Inherits:
-
Object
- Object
- ExcelXml::Workbook::Parser
- Defined in:
- lib/excelxml/workbook.rb
Instance Attribute Summary collapse
-
#unidentified_worksheets ⇒ Object
readonly
Returns the value of attribute unidentified_worksheets.
Instance Method Summary collapse
- #[](worksheet_parser_class) ⇒ Object
-
#initialize(workbook_xml, opts = {}) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(workbook_xml, opts = {}) ⇒ Parser
Returns a new instance of Parser.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/excelxml/workbook.rb', line 14 def initialize workbook_xml, opts={} only_these_worksheets = [opts.delete(:only_these_worksheets)].flatten.compact @worksheet_parser_classes = [opts.delete(:worksheet_parsers)].flatten.compact @worksheet_parser_hash = @worksheet_parser_classes.each_with_object({}) {|wspc, hsh| hsh[wspc] = [] } raise ArgumentError, "unknown options #{opts.keys.inspect}" unless opts.empty? @unidentified_worksheets = [] ExcelXml::Workbook.parse(workbook_xml, single: true).worksheets.each do |worksheet| next if !only_these_worksheets.empty? and !only_these_worksheets.include?(worksheet.name) worksheet_identified = false worksheet.rows.each_with_index do |row, row_idx| worksheet_identifiers.each do |wsp| if wsp.is_header? (row_idx+1), row add_worksheet_parser(wsp.class, worksheet, row_idx) worksheet_identified = true break end end break if worksheet_identified end unless @worksheet_parser_classes.empty? @unidentified_worksheets << worksheet unless worksheet_identified end end |
Instance Attribute Details
#unidentified_worksheets ⇒ Object (readonly)
Returns the value of attribute unidentified_worksheets.
13 14 15 |
# File 'lib/excelxml/workbook.rb', line 13 def unidentified_worksheets @unidentified_worksheets end |
Instance Method Details
#[](worksheet_parser_class) ⇒ Object
37 38 39 |
# File 'lib/excelxml/workbook.rb', line 37 def [] worksheet_parser_class @worksheet_parser_hash[worksheet_parser_class] end |