Created
October 25, 2012 14:57
-
-
Save stevenhuey/3953082 to your computer and use it in GitHub Desktop.
Before Mantle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation CBCosmDatastream | |
- (id)initWithAttributes:(NSDictionary*)attributes | |
{ | |
self = [super init]; | |
if (self) | |
{ | |
if (!attributes) | |
{ | |
return nil; | |
} | |
for (NSString* key in attributes) | |
{ | |
[self setValue:[attributes valueForKey:key] | |
forKey:key]; | |
} | |
} | |
return self; | |
} | |
#pragma mark - Equality | |
- (NSUInteger)hash | |
{ | |
return [self.datastreamId hash]; | |
} | |
- (BOOL)isEqual:(id)object | |
{ | |
if ([object isKindOfClass:[CBCosmDatastream class]]) | |
{ | |
CBCosmDatastream* otherDatastream = (CBCosmDatastream*)object; | |
return [self.datastreamId isEqualToNumber:otherDatastream.datastreamId]; | |
} | |
else | |
{ | |
return NO; | |
} | |
} | |
#pragma mark - KVC | |
- (void)setValue:(id)value forKey:(NSString*)key | |
{ | |
if ([key isEqualToString:@"id"]) | |
{ | |
[super setValue:value forKey:@"datastreamId"]; | |
} | |
else if ([key isEqualToString:@"at"]) | |
{ | |
[super setValue:value forKey:@"updated"]; | |
} | |
else if ([key isEqualToString:@"current_value"]) | |
{ | |
[super setValue:value forKey:@"value"]; | |
} | |
else if ([key isEqualToString:@"min_value"]) | |
{ | |
[super setValue:value forKey:@"minValue"]; | |
} | |
else if ([key isEqualToString:@"max_value"]) | |
{ | |
[super setValue:value forKey:@"maxValue"]; | |
} | |
else if ([key isEqualToString:@"datapoints"]) | |
{ | |
if ([value isKindOfClass:[NSArray class]]) | |
{ | |
NSArray* values = (NSArray*)value; | |
NSMutableArray* datapoints = [NSMutableArray arrayWithCapacity:[values count]]; | |
for (NSDictionary* attributes in values) | |
{ | |
CBCosmDatapoint* datapoint = [[CBCosmDatapoint alloc] initWithAttributes:attributes]; | |
[datapoints addObject:datapoint]; | |
} | |
_datapoints = datapoints; | |
} | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment