Class: ExcelUtils::Sheet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/excel_utils/sheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, spreadsheet, normalize_column_names: false) ⇒ Sheet

Returns a new instance of Sheet.



8
9
10
11
12
# File 'lib/excel_utils/sheet.rb', line 8

def initialize(name, spreadsheet, normalize_column_names: false)
  @name = name
  @spreadsheet = spreadsheet
  @normalize_column_names = normalize_column_names
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/excel_utils/sheet.rb', line 6

def name
  @name
end

#normalize_column_namesObject (readonly)

Returns the value of attribute normalize_column_names.



6
7
8
# File 'lib/excel_utils/sheet.rb', line 6

def normalize_column_names
  @normalize_column_names
end

Instance Method Details

#column_namesObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/excel_utils/sheet.rb', line 14

def column_names
  @column_names ||= begin
    if sheet.first_row
      first_row = sheet.row sheet.first_row
      normalize_column_names ? first_row.map { |name| normalize_column name } : first_row
    else
      []
    end
  end
end

#each(&block) ⇒ Object



25
26
27
# File 'lib/excel_utils/sheet.rb', line 25

def each(&block)
  rows.each(&block)
end