Skip to content

Instantly share code, notes, and snippets.

@Dysperen
Last active October 5, 2016 10:27
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 Dysperen/a611b02e70e5160630e6598354309f2f to your computer and use it in GitHub Desktop.
Save Dysperen/a611b02e70e5160630e6598354309f2f to your computer and use it in GitHub Desktop.
# @!visibility private
class Loader
require_relative 'excel/_kincom'
require_relative 'excel/_vo2max'
# Måske flytte error-messages til en seperat fil?
NEGATIVE = "There is a negative value. That doesn't make sense. Oxygen consumption cannot be negative"
IS_EMPTY = "The data array is empty. This cannot be good."
WRONG_FILE = "Excel worksheet is not as expected. Is it the raw output?"
def initialize(file)
@file = File.open(file, "r")
self
end
def excel(request)
raise ArgumentError, "No file has been loaded." if @file.nil?
case request
when :kincom
KincomLoader.new(@file)
when :vo2max
Vo2maxLoader.new(@file)
else
raise ArgumentError, "#{request.to_s} is not implemented in the loader module."
end
end
end
class TestLoading < Minitest::Test
include TestHelperLoading
def setup
@kincom_file = './mockups/kincom/test_file.xlsx'
@vo2max_file = './mockups/vo2max/test_cosmed.xlsx'
end
def test_exceptions
assert_raises ArgumentError do Loader.new(@kincom_file).excel(:invalid) end;
end
def test_interface
assert_instance_of KincomLoader, Loader.new(@kincom_file).excel(:kincom)
assert_instance_of Vo2maxLoader, Loader.new(@vo2max_file).excel(:vo2max)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment