Class: FileReader::Excel

Inherits:
Connector::ExcelReadConnector show all
Defined in:
lib/mylookup/reader.rb

Overview

Contains the functionalities of reading Excel data

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Connector::ExcelReadConnector

#column_exists?, #sheet_exists?

Constructor Details

#initialize(path, sht_name, col_name) ⇒ Excel

Returns a new instance of Excel.



11
12
13
14
15
16
# File 'lib/mylookup/reader.rb', line 11

def initialize(path, sht_name, col_name)
    super(path)
    @sht = @wb.sheet(sht_name)
    @col = col_name
    @data = nil
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



9
10
11
# File 'lib/mylookup/reader.rb', line 9

def data
  @data
end

Instance Method Details

#read(match: {}, hide: {}, q_meth: :find) ⇒ Object



18
19
20
21
22
23
# File 'lib/mylookup/reader.rb', line 18

def read(match: {}, hide: {}, q_meth: :find)
    aoa = @sht.parse(@col.to_sym => @col)
    @data = aoa.collect { |item| item[@col.to_sym].to_s.downcase }
    @data = @data.uniq
    return "Excel Data contains #{@data.size} row(s)\nExcel First Record => #{@data[0]}"
end