Created
March 30, 2009 02:44
-
-
Save tomjadams/87609 to your computer and use it in GitHub Desktop.
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
// OLD | |
- (NSDictionary *)parsePerks:(NSArray *)perks { | |
NSMutableArray *convertedPerks = [NSMutableArray arrayWithCapacity:[perks count]]; | |
for (NSDictionary *perk in perks) { | |
PLPerk *convertedPerk = [[PLPerk alloc] initWithProgramName:[perk objectForKey:@"program_name"] | |
shortDescription:[perk objectForKey:@"perk_title"] longDescription:[perk objectForKey:@"perk_desc"] | |
location:[self parseLocation:[perk objectForKey:@"locations"]]]; | |
[convertedPerks addObject:convertedPerk]; | |
[convertedPerk release]; | |
} | |
return convertedPerks; | |
} | |
- (FKOption *)parseLocation:(NSArray *)locations { | |
return locations == nil || [locations count] == 0 ? [FKOption none] : [FKOption fromNil:[[locations objectAtIndex:0] objectForKey:@"geo_location"]]; | |
} | |
// NEW | |
- (NSDictionary *)parsePerks:(NSArray *)perks { | |
NSArray *parsedPerks = [perks map:[NSArray liftFunction:functionTS(self, perkFromDictionary:)]]; | |
return [parsedPerks groupByKey:functionS(programName)]; | |
} | |
- (PLPerk *)perkFromDictionary:(NSDictionary *)perk { | |
return [[[PLPerk alloc] initWithProgramName:[perk objectForKey:@"program_name"] shortDescription:[perk objectForKey:@"perk_title"] | |
longDescription:[perk objectForKey:@"perk_desc"] location:[self parseLocation:[perk objectForKey:@"locations"]]] autorelease]; | |
} | |
- (FKOption *)parseLocation:(NSArray *)locations { | |
return locations == nil || [locations count] == 0 ? [FKOption none] : [FKOption fromNil:[[locations objectAtIndex:0] objectForKey:@"geo_location"]]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment