// // P4FilePath.m // P4Menu // // Created by Michael Bishop on 1/16/12. // Copyright (c) 2012 __MyCompanyName__. All rights reserved. // #import "P4FilePath.h" @interface P4FilePath () @property (nonatomic, readwrite, assign) P4FilePathType type; @property (nonatomic, readwrite, copy) NSString * path; @property (nonatomic, readwrite, copy) NSString * revision; @end @implementation P4FilePath @synthesize type = _type; @synthesize path = _path; @synthesize revision = _revision; +(id)filePathParsedFromString:(NSString*)string { P4FilePathType type = [string hasPrefix:@"//"] ? SERVER : LOCAL ; NSString * path = nil; NSString * revision = nil; NSArray * components = [string componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"#"]]; if ( [components count] == 0 ) return nil; path = [components objectAtIndex:0]; if ( type == SERVER ) path = [path substringFromIndex:1]; if ( [components count] > 1 ) revision = [components objectAtIndex:1]; return [self filePathWithType:type path:path revision:revision]; } +(id)filePathWithType:(P4FilePathType)type path:(NSString*)path revision:(NSString*)revision { return [[[self alloc] initWithType:type path:path revision:revision] autorelease]; } -(id)initWithType:(P4FilePathType)type path:(NSString*)path revision:(NSString*)revision { if ( !(self = [super init]) ) return nil; self.type = type; self.path = path; self.revision = revision; return self; } -(void)dealloc { [_path release]; [_revision release]; [super dealloc]; } -(NSString*)description { return self.formattedString; } +(NSSet*)keyPathsForValuesAffectingFormattedPath { return [NSSet setWithObjects:@"path", @"type", nil]; } -(NSString*)formattedPath { return self.type == SERVER ? [@"/" stringByAppendingString:self.path] : self.path; } +(NSSet*)keyPathsForValuesAffectingFormattedString { return [NSSet setWithObjects:@"formattedPath", @"revision", nil]; } -(NSString*)formattedString { if ( !self.revision ) return self.formattedPath; return [NSString stringWithFormat:@"%@#%@", self.formattedPath, self.revision]; } @end @implementation P4MutableFilePath // inherited from P4FilePath private methods @dynamic type; @dynamic path; @dynamic revision; @end