Class: Topographer::Importer::Input::Roo

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/topographer/importer/input/roo.rb

Instance Method Summary collapse

Constructor Details

#initialize(roo_sheet, header_row = 1, data_row = 2) ⇒ Roo

Returns a new instance of Roo.



4
5
6
7
8
9
# File 'lib/topographer/importer/input/roo.rb', line 4

def initialize(roo_sheet, header_row=1, data_row=2)
  @sheet = roo_sheet
  @header = @sheet.row(header_row).map(&:strip)
  @start_data_row = data_row
  @end_data_row = @sheet.last_row
end

Instance Method Details

#eachObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/topographer/importer/input/roo.rb', line 20

def each
  @start_data_row.upto @end_data_row do |row_number|
    data = @sheet.row(row_number)
    source_identifier = "Row: #{row_number}"

    if data.reject{ |column| column.blank? }.any?
      yield Topographer::Importer::Input::SourceData.new(
        source_identifier,
        Hash[@header.zip(data)]
      )
    end
  end
end

#get_headerObject



11
12
13
# File 'lib/topographer/importer/input/roo.rb', line 11

def get_header
  @header
end

#input_identifierObject



15
16
17
18
# File 'lib/topographer/importer/input/roo.rb', line 15

def input_identifier
  #This is apparently how you get the name of the sheet...this makes me sad
  @sheet.default_sheet
end