-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBCCitationAuthor.m
82 lines (55 loc) · 2.3 KB
/
BCCitationAuthor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// BCCitationAuthor.m
// Caravan
//
// Created by Tom Houpt on 15/3/16.
// Copyright (c) 2015 Tom Houpt. All rights reserved.
//
#import "BCCitationAuthor.h"
@implementation BCCitationAuthor
@synthesize indexName;
@synthesize givenName;
@synthesize initials;
@synthesize orcid;
-(id)init; {
return [self initWithLastNameAndInitialsString:NULL];
}
-(id)initWithLastNameAndInitialsString:(NSString *)authorName; {
self = [super init];
if (self) {
indexName = @"Anonymous";
givenName = [NSString string];
initials = [NSString string];
orcid = [NSString string];
if (authorName != NULL && [authorName length] > 0) {
NSArray *parts = [authorName componentsSeparatedByString:@","];
indexName = [parts firstObject];
NSArray *restOfParts = [parts subarrayWithRange: NSMakeRange( 1 , [parts count] - 1 )];
initials = [[restOfParts componentsJoinedByString: @","] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
}
}
return self;
}
-(NSDictionary *)packIntoDictionary; {
NSDictionary *theDictionary = [NSDictionary
dictionaryWithObjects:@[
indexName,
givenName,
initials,
orcid
]
forKeys:@[
kCitationAuthorIndexNameKey,
kCitationAuthorGivenNameKey,
kCitationAuthorInitialsKey,
kCitationAuthorOrcidKey,
]
];
return theDictionary;
}
-(void)unpackFromDictionary:(NSDictionary *)theDictionary; {
for (NSString *key in [theDictionary allKeys]) {
[self setValue:[theDictionary objectForKey:key] forKey:key];
}
}
@end