Class: ExcelUtils::Workbook
- Inherits:
-
Object
- Object
- ExcelUtils::Workbook
- Defined in:
- lib/excel_utils/workbook.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) ⇒ Workbook
constructor
A new instance of Workbook.
- #sheets ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(filename, normalize_column_names: false, extension: nil) ⇒ Workbook
Returns a new instance of Workbook.
6 7 8 9 10 |
# File 'lib/excel_utils/workbook.rb', line 6 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.
4 5 6 |
# File 'lib/excel_utils/workbook.rb', line 4 def filename @filename end |
#normalize_column_names ⇒ Object (readonly)
Returns the value of attribute normalize_column_names.
4 5 6 |
# File 'lib/excel_utils/workbook.rb', line 4 def normalize_column_names @normalize_column_names end |
Instance Method Details
#[](sheet_name) ⇒ Object
18 19 20 |
# File 'lib/excel_utils/workbook.rb', line 18 def [](sheet_name) sheets.detect { |sheet| sheet.name == sheet_name } end |
#sheets ⇒ Object
12 13 14 15 16 |
# File 'lib/excel_utils/workbook.rb', line 12 def sheets @sheets ||= spreadsheet.sheets.map do |name| Sheet.new name, spreadsheet, normalize_column_names: normalize_column_names end end |
#to_h ⇒ Object
22 23 24 25 26 |
# File 'lib/excel_utils/workbook.rb', line 22 def to_h sheets.each_with_object({}) do |sheet, hash| hash[sheet.name] = sheet.to_a end end |