Class: ExcelUtils::Workbooks::CSV

Inherits:
Object
  • Object
show all
Defined in:
lib/excel_utils/workbooks/csv.rb

Constant Summary collapse

SHEET_NAME =
'default'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, normalize_column_names: false) ⇒ CSV



9
10
11
12
13
14
15
16
# File 'lib/excel_utils/workbooks/csv.rb', line 9

def initialize(filename, normalize_column_names: false)
  @filename = filename
  @normalize_column_names = normalize_column_names

  @sheet = Sheets::CSV.new name: SHEET_NAME,
                           normalize_column_names: normalize_column_names,
                           filename: filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/excel_utils/workbooks/csv.rb', line 7

def filename
  @filename
end

#normalize_column_namesObject (readonly)

Returns the value of attribute normalize_column_names.



7
8
9
# File 'lib/excel_utils/workbooks/csv.rb', line 7

def normalize_column_names
  @normalize_column_names
end

Instance Method Details

#[](sheet_name) ⇒ Object



22
23
24
# File 'lib/excel_utils/workbooks/csv.rb', line 22

def [](sheet_name)
  sheet_name == SHEET_NAME ? sheet : nil
end

#sheetsObject



18
19
20
# File 'lib/excel_utils/workbooks/csv.rb', line 18

def sheets
  [sheet]
end

#to_hObject



26
27
28
# File 'lib/excel_utils/workbooks/csv.rb', line 26

def to_h
  {SHEET_NAME => sheet.to_a}
end