Rather than calling cop_log.read_spreadsheet
how can I call the method read_spreadsheet
directly inside my class when I use ChangeOrderLog.new('path/to/file')
?
cop_log.read_spreadsheet
populates the @cop_log
hash with the data from an excel spreadsheet, is there any way I can populate my hash from within my ChangeOrderLog class instead of outside of it?
require 'creek'
class ChangeOrderLog
attr_reader :creek, :sheet
attr_accessor :cop_log
def initialize(file)
@creek = Creek::Book.new file
@sheet= @creek.sheets[0]
@cop_log = {}
end
def read_spreadsheet
sheet.rows.each { |row| cop_log.merge!(row) }
end
def job_number
return cop_log['G1']
end
end
cop_log = ChangeOrderLog.new('path/to/file')
cop_log.read_spreadsheet
puts cop_log.job_number