-
-
Save Dysp/76f598d0abc39ab439954f9cc4529c27 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative '_kincom' | |
module LoadingHelper | |
def self.included(other) other.include KincomLoader; end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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