Class: ExcelUtils::Workbooks::Excel
- Inherits:
-
Object
- Object
- ExcelUtils::Workbooks::Excel
- Defined in:
- lib/excel_utils/workbooks/excel.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#normalize_column_names ⇒ Object
readonly
Returns the value of attribute normalize_column_names.
Instance Method Summary collapse
- #[](sheet_name) ⇒ Object
-
#initialize(filename, normalize_column_names: false, extension: nil) ⇒ Excel
constructor
A new instance of Excel.
- #sheets ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(filename, normalize_column_names: false, extension: nil) ⇒ Excel
Returns a new instance of Excel.
7 8 9 10 11 |
# File 'lib/excel_utils/workbooks/excel.rb', line 7 def initialize(filename, normalize_column_names: false, extension: nil) @filename = filename @normalize_column_names = normalize_column_names @spreadsheet = Roo::Spreadsheet.open filename, extension: extension end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/excel_utils/workbooks/excel.rb', line 5 def filename @filename end |
#normalize_column_names ⇒ Object (readonly)
Returns the value of attribute normalize_column_names.
5 6 7 |
# File 'lib/excel_utils/workbooks/excel.rb', line 5 def normalize_column_names @normalize_column_names end |
Instance Method Details
#[](sheet_name) ⇒ Object
21 22 23 |
# File 'lib/excel_utils/workbooks/excel.rb', line 21 def [](sheet_name) sheets.detect { |sheet| sheet.name == sheet_name } end |
#sheets ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/excel_utils/workbooks/excel.rb', line 13 def sheets @sheets ||= spreadsheet.sheets.map do |name| sheet_class.new name: name, normalize_column_names: normalize_column_names, spreadsheet: spreadsheet end end |
#to_h ⇒ Object
25 26 27 28 29 |
# File 'lib/excel_utils/workbooks/excel.rb', line 25 def to_h sheets.each_with_object({}) do |sheet, hash| hash[sheet.name] = sheet.to_a end end |