Convert data reading methods to args classes
parent
82a2538180
commit
2dfaf64ef7
|
|
@ -1,5 +1,6 @@
|
||||||
require 'roo'
|
require 'roo'
|
||||||
require 'csv'
|
require 'csv'
|
||||||
|
require 'squib/args/input_file'
|
||||||
|
|
||||||
module Squib
|
module Squib
|
||||||
|
|
||||||
|
|
@ -22,10 +23,9 @@ module Squib
|
||||||
# @return [Hash] a hash of arrays based on columns in the spreadsheet
|
# @return [Hash] a hash of arrays based on columns in the spreadsheet
|
||||||
# @api public
|
# @api public
|
||||||
def xlsx(opts = {})
|
def xlsx(opts = {})
|
||||||
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
input = Args::InputFile.new(file: 'deck.xlsx').load!(opts)
|
||||||
opts = Squib::InputHelpers.fileify(opts)
|
s = Roo::Excelx.new(input.file[0])
|
||||||
s = Roo::Excelx.new(opts[:file])
|
s.default_sheet = s.sheets[input.sheet[0]]
|
||||||
s.default_sheet = s.sheets[opts[:sheet]]
|
|
||||||
data = {}
|
data = {}
|
||||||
s.first_column.upto(s.last_column) do |col|
|
s.first_column.upto(s.last_column) do |col|
|
||||||
header = s.cell(s.first_row,col).to_s
|
header = s.cell(s.first_row,col).to_s
|
||||||
|
|
@ -61,9 +61,10 @@ module Squib
|
||||||
# @return [Hash] a hash of arrays based on columns in the table
|
# @return [Hash] a hash of arrays based on columns in the table
|
||||||
# @api public
|
# @api public
|
||||||
def csv(opts = {})
|
def csv(opts = {})
|
||||||
|
file = Args::InputFile.new(file: 'deck.csv').load!(opts).file[0]
|
||||||
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
||||||
opts = Squib::InputHelpers.fileify(opts)
|
# opts = Squib::InputHelpers.fileify(opts)
|
||||||
table = CSV.read(opts[:file], headers: true, converters: :numeric)
|
table = CSV.read(file, headers: true, converters: :numeric)
|
||||||
check_duplicate_csv_headers(table)
|
check_duplicate_csv_headers(table)
|
||||||
hash = Hash.new
|
hash = Hash.new
|
||||||
table.headers.each do |header|
|
table.headers.each do |header|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,14 @@ module Squib
|
||||||
class InputFile
|
class InputFile
|
||||||
include ArgLoader
|
include ArgLoader
|
||||||
|
|
||||||
def initialize
|
def initialize(dsl_method_default = {})
|
||||||
|
@dsl_method_default = dsl_method_default
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.parameters
|
def self.parameters
|
||||||
{ file: nil }
|
{ file: nil,
|
||||||
|
sheet: 0,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.expanding_parameters
|
def self.expanding_parameters
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue