//
//  NSString+YSRACKeyPathUtilities.m
//  ReactiveObjC
//
//  Created by Uri Baghin on 05/05/2013.
//  Copyright (c) 2013 GitHub, Inc. All rights reserved.
//

#import "NSString+YSRACKeyPathUtilities.h"

@implementation NSString (YSRACKeyPathUtilities)

- (NSArray *)ysrac_keyPathComponents {
	if (self.length == 0) {
		return nil;
	}
	return [self componentsSeparatedByString:@"."];
}

- (NSString *)ysrac_keyPathByDeletingLastKeyPathComponent {
	NSUInteger lastDotIndex = [self rangeOfString:@"." options:NSBackwardsSearch].location;
	if (lastDotIndex == NSNotFound) {
		return nil;
	}
	return [self substringToIndex:lastDotIndex];
}

- (NSString *)ysrac_keyPathByDeletingFirstKeyPathComponent {
	NSUInteger firstDotIndex = [self rangeOfString:@"."].location;
	if (firstDotIndex == NSNotFound) {
		return nil;
	}
	return [self substringFromIndex:firstDotIndex + 1];
}

@end
