Class: SimpleXlsxReader::Document
- Inherits:
-
Object
- Object
- SimpleXlsxReader::Document
- Defined in:
- lib/simple_xlsx_reader/document.rb
Overview
Main class for the public API. See the README for usage examples, or read the code, it’s pretty friendly.
Defined Under Namespace
Instance Attribute Summary collapse
-
#string_or_io ⇒ Object
readonly
Returns the value of attribute string_or_io.
Instance Method Summary collapse
-
#initialize(legacy_file_path = nil, file_path: nil, string_or_io: nil) ⇒ Document
constructor
A new instance of Document.
- #sheets ⇒ Object
-
#to_hash ⇒ Object
Expensive because it slurps all the sheets into memory, probably only appropriate for testing.
Constructor Details
#initialize(legacy_file_path = nil, file_path: nil, string_or_io: nil) ⇒ Document
Returns a new instance of Document.
13 14 15 16 17 |
# File 'lib/simple_xlsx_reader/document.rb', line 13 def initialize(legacy_file_path = nil, file_path: nil, string_or_io: nil) fail(ArgumentError, 'either file_path or string_or_io must be provided') if legacy_file_path.nil? && file_path.nil? && string_or_io.nil? @string_or_io = string_or_io || File.new(legacy_file_path || file_path) end |
Instance Attribute Details
#string_or_io ⇒ Object (readonly)
Returns the value of attribute string_or_io.
11 12 13 |
# File 'lib/simple_xlsx_reader/document.rb', line 11 def string_or_io @string_or_io end |
Instance Method Details
#sheets ⇒ Object
19 20 21 |
# File 'lib/simple_xlsx_reader/document.rb', line 19 def sheets @sheets ||= Loader.new(string_or_io).init_sheets end |
#to_hash ⇒ Object
Expensive because it slurps all the sheets into memory, probably only appropriate for testing
25 26 27 |
# File 'lib/simple_xlsx_reader/document.rb', line 25 def to_hash sheets.each_with_object({}) { |sheet, acc| acc[sheet.name] = sheet.rows.to_a; } end |