Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions code/internal/+openminds/+abstract/TypesEnumeration.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
properties (SetAccess=immutable)
ClassName (1,1) string
AliasClassName (1,1) string
TypeURI (1,1) string
end

methods
function obj = TypesEnumeration(name)
obj.ClassName = name;
obj.AliasClassName = obj.createAliasClassName();
obj.TypeURI = obj.getTypeURI();

Check warning on line 13 in code/internal/+openminds/+abstract/TypesEnumeration.m

View check run for this annotation

Codecov / codecov/patch

code/internal/+openminds/+abstract/TypesEnumeration.m#L13

Added line #L13 was not covered by tests
end
end

Expand Down Expand Up @@ -38,23 +40,96 @@
aliasClassName = strjoin(classNameParts([1,2,end]), '.');
end
end

function typeURI = getTypeURI(obj)
if obj.ClassName == "None"
typeURI = "None";

Check warning on line 46 in code/internal/+openminds/+abstract/TypesEnumeration.m

View check run for this annotation

Codecov / codecov/patch

code/internal/+openminds/+abstract/TypesEnumeration.m#L45-L46

Added lines #L45 - L46 were not covered by tests
else
typeURI = eval(sprintf('%s.X_TYPE', obj.ClassName));

Check warning on line 48 in code/internal/+openminds/+abstract/TypesEnumeration.m

View check run for this annotation

Codecov / codecov/patch

code/internal/+openminds/+abstract/TypesEnumeration.m#L48

Added line #L48 was not covered by tests
end
end
end

methods (Static)
function typeEnum = fromClassName(className)

if ischar(className)
className = string(className);
% fromClassName - Get a Type enum from a class name
%
% Syntax:
% typeEnum = openminds.enum.Types.fromClassName(className) Converts
% the provided class name(s) into the appropriate enumeration value (s).
%
% Input Arguments:
% className - A string array representing the class name(s) to be
% converted.
%
% Output Arguments:
% typeEnum - The corresponding enumeration value(s) from
% openminds.enum.Types.
%
% Example:
%
% openminds.enum.Types.fromClassName("openminds.core.Person")
%
% ans =
%
% Types enumeration
%
% Person

arguments
className (1,:) string
end

if numel(className) > 1
if iscell(className); className = string(className); end
typeEnum = arrayfun(@(str) openminds.enum.Types.fromClassName(str), className);
return
end

splitName = strsplit(className, '.');
typeEnum = openminds.enum.Types(splitName{end});
end

function typeEnum = fromAtType(typeName)
% fromAtType - Convert an @type string to its corresponding enumeration.
%
% Syntax:
% typeEnum = openminds.enum.Types.fromAtType(typeName) Converts the
% provided @type string into the appropriate enumeration value.
%
% Input Arguments:
% typeName - A string array representing the @type to be converted.
% The @type URI is expected to match Base URI for the
% currently active openMINDS version
%
% Output Arguments:
% typeEnum - The corresponding enumeration value(s) from
% openminds.enum.Types.
%
% Example:
%
% openminds.enum.Types.fromAtType("https://openminds.om-i.org/types/Person")
%
% ans =
%
% Types enumeration
%
% Person

arguments
typeName (1,:) string
end

assert(all(startsWith(typeName, openminds.constant.BaseURI)), ...
'OPENMINDS_MATLAB:Types:InvalidAtType', ...
'Expected @type to start with "%s"', openminds.constant.BaseURI)

Check warning on line 124 in code/internal/+openminds/+abstract/TypesEnumeration.m

View check run for this annotation

Codecov / codecov/patch

code/internal/+openminds/+abstract/TypesEnumeration.m#L122-L124

Added lines #L122 - L124 were not covered by tests

if numel(typeName) > 1
typeEnum = arrayfun(@(str) openminds.enum.Types.fromAtType(str), typeName);
return

Check warning on line 128 in code/internal/+openminds/+abstract/TypesEnumeration.m

View check run for this annotation

Codecov / codecov/patch

code/internal/+openminds/+abstract/TypesEnumeration.m#L126-L128

Added lines #L126 - L128 were not covered by tests
end

splitName = strsplit(typeName, '/');
typeEnum = eval(sprintf('openminds.enum.Types.%s', splitName{end}));

Check warning on line 132 in code/internal/+openminds/+abstract/TypesEnumeration.m

View check run for this annotation

Codecov / codecov/patch

code/internal/+openminds/+abstract/TypesEnumeration.m#L131-L132

Added lines #L131 - L132 were not covered by tests
end
end
end