Skip to content

Instantly share code, notes, and snippets.

@Dysp

Dysp/_kincom.rb Secret

Last active July 29, 2016 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dysp/76f598d0abc39ab439954f9cc4529c27 to your computer and use it in GitHub Desktop.
Save Dysp/76f598d0abc39ab439954f9cc4529c27 to your computer and use it in GitHub Desktop.
module KincomLoader
def load_file(file)
loaded_file = RubyXL::Parser.parse(file).worksheets
data = extract_values(loaded_file)
return File.basename(file), data
end
def extract_values(sheets)
array = []
sheets.each do |sheet|
array << sheet.map { |row| row[1].value.to_f }
end
array
end
module_function :load_file
end
require_relative '_kincom'
module LoadingHelper
def self.included(other) other.include KincomLoader; end
end
def test_kincom_loading
# Test-filen loades
rubyxl = KincomLoader::load_file(FILE)
# Vi skulle meget gerne få et array tilbage
assert_instance_of Array, rubyxl[1]
#... som består af
rubyxl[1].each do |r|
assert_instance_of Array, r
end
end
$debug.msg
require_relative './kincom/kincom'
require_relative './validation/validation_helper.rb'
require_relative './loading/loading_helper.rb'
class XerciseClass
include ValidationHelper
include LoadingHelper
attr_reader :whoamI
def initialize
@whoamI = "I am an Xercise instance. I should not ever be called. Should I maybe be a module instead?"
end
def kincom(file, options)
validate(file, options)
data = KincomLoader::load_file(file)
Kincom.new(data[1], options.merge!({ filename: data[0] }))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment