diff --git a/ShoulderCase/@SCaseIDParser/SCaseIDParser.m b/ShoulderCase/@SCaseIDParser/SCaseIDParser.m index 051aa92..1d6177d 100644 --- a/ShoulderCase/@SCaseIDParser/SCaseIDParser.m +++ b/ShoulderCase/@SCaseIDParser/SCaseIDParser.m @@ -1,76 +1,74 @@ classdef SCaseIDParser < handle - - properties (Constant, Hidden = true) - maxDigits = 3; - SCaseValidTypes = 'NP'; - end - - - properties (Access = private) + maxDigits + SCaseValidTypes rawID end methods function obj = SCaseIDParser(rawID) - obj.rawID = []; - if ischar(rawID) - obj.rawID = rawID; - end + obj.rawID = rawID; + assert(ischar(rawID),'Input argument must be a char array.'); + + obj.maxDigits = str2num(ConfigFileExtractor.getVariable('maxSCaseIDDigits')); + assert(not(isempty(obj.maxDigits)),'maxDigits property is empty'); + + obj.SCaseValidTypes = ConfigFileExtractor.getVariable('SCaseIDValidTypes'); + assert(not(isempty(obj.SCaseValidTypes)),'SCaseValidTypes property is empty'); end function output = isValidID(obj) - types = SCaseIDParser.SCaseValidTypes; - maxDigits = SCaseIDParser.maxDigits; + types = obj.SCaseValidTypes; + maxDigits = obj.maxDigits; output = obj.SCaseIDHasTypesAndMaxDigits(types,maxDigits); end function output = isNormalCase(obj) types = 'N'; - maxDigits = SCaseIDParser.maxDigits; + maxDigits = obj.maxDigits; output = obj.SCaseIDHasTypesAndMaxDigits(types,maxDigits); end function output = isPathologicalCase(obj) types = 'P'; - maxDigits = SCaseIDParser.maxDigits; + maxDigits = obj.maxDigits; output = obj.SCaseIDHasTypesAndMaxDigits(types,maxDigits); end function output = getID(obj) output = obj.rawID; end function output = getIDWithNumberOfDigits(obj,size) type = obj.getCaseType; number = obj.getCaseNumber; fillingZeros = repmat('0',1,size-length(type)-length(number)); output = [type fillingZeros number]; end end methods (Access = private) function output = SCaseIDHasTypesAndMaxDigits(obj,types,maxDigits) expression = ['[' types ']\d{1,' num2str(maxDigits) '}']; output = textMatchesExpression(obj.rawID,expression); end function output = getCaseType(obj) output = obj.rawID(1); end function output = getCaseNumber(obj) output = obj.rawID(2:end); end end end