Skip to content

Commit 26ba40c

Browse files
authored
Update TypesEnumeration - Add utility properties / methods (#36)
* Update TypesEnumeration - Add utility properties / methods
1 parent e929735 commit 26ba40c

File tree

1 file changed

+79
-4
lines changed

1 file changed

+79
-4
lines changed

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

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
properties (SetAccess=immutable)
44
ClassName (1,1) string
55
AliasClassName (1,1) string
6+
TypeURI (1,1) string
67
end
78

89
methods
910
function obj = TypesEnumeration(name)
1011
obj.ClassName = name;
1112
obj.AliasClassName = obj.createAliasClassName();
13+
obj.TypeURI = obj.getTypeURI();
1214
end
1315
end
1416

@@ -38,23 +40,96 @@
3840
aliasClassName = strjoin(classNameParts([1,2,end]), '.');
3941
end
4042
end
43+
44+
function typeURI = getTypeURI(obj)
45+
if obj.ClassName == "None"
46+
typeURI = "None";
47+
else
48+
typeURI = eval(sprintf('%s.X_TYPE', obj.ClassName));
49+
end
50+
end
4151
end
4252

4353
methods (Static)
4454
function typeEnum = fromClassName(className)
45-
46-
if ischar(className)
47-
className = string(className);
55+
% fromClassName - Get a Type enum from a class name
56+
%
57+
% Syntax:
58+
% typeEnum = openminds.enum.Types.fromClassName(className) Converts
59+
% the provided class name(s) into the appropriate enumeration value (s).
60+
%
61+
% Input Arguments:
62+
% className - A string array representing the class name(s) to be
63+
% converted.
64+
%
65+
% Output Arguments:
66+
% typeEnum - The corresponding enumeration value(s) from
67+
% openminds.enum.Types.
68+
%
69+
% Example:
70+
%
71+
% openminds.enum.Types.fromClassName("openminds.core.Person")
72+
%
73+
% ans =
74+
%
75+
% Types enumeration
76+
%
77+
% Person
78+
79+
arguments
80+
className (1,:) string
4881
end
4982

5083
if numel(className) > 1
51-
if iscell(className); className = string(className); end
5284
typeEnum = arrayfun(@(str) openminds.enum.Types.fromClassName(str), className);
5385
return
5486
end
5587

5688
splitName = strsplit(className, '.');
5789
typeEnum = openminds.enum.Types(splitName{end});
5890
end
91+
92+
function typeEnum = fromAtType(typeName)
93+
% fromAtType - Convert an @type string to its corresponding enumeration.
94+
%
95+
% Syntax:
96+
% typeEnum = openminds.enum.Types.fromAtType(typeName) Converts the
97+
% provided @type string into the appropriate enumeration value.
98+
%
99+
% Input Arguments:
100+
% typeName - A string array representing the @type to be converted.
101+
% The @type URI is expected to match Base URI for the
102+
% currently active openMINDS version
103+
%
104+
% Output Arguments:
105+
% typeEnum - The corresponding enumeration value(s) from
106+
% openminds.enum.Types.
107+
%
108+
% Example:
109+
%
110+
% openminds.enum.Types.fromAtType("https://openminds.om-i.org/types/Person")
111+
%
112+
% ans =
113+
%
114+
% Types enumeration
115+
%
116+
% Person
117+
118+
arguments
119+
typeName (1,:) string
120+
end
121+
122+
assert(all(startsWith(typeName, openminds.constant.BaseURI)), ...
123+
'OPENMINDS_MATLAB:Types:InvalidAtType', ...
124+
'Expected @type to start with "%s"', openminds.constant.BaseURI)
125+
126+
if numel(typeName) > 1
127+
typeEnum = arrayfun(@(str) openminds.enum.Types.fromAtType(str), typeName);
128+
return
129+
end
130+
131+
splitName = strsplit(typeName, '/');
132+
typeEnum = eval(sprintf('openminds.enum.Types.%s', splitName{end}));
133+
end
59134
end
60135
end

0 commit comments

Comments
 (0)