/Mobile/iPhone/StoffiRemote/StoffiRemote/Configuration.m
Objective C | 59 lines | 34 code | 18 blank | 7 comment | 14 complexity | 86c945a817f2b2905b085dfc01188ec7 MD5 | raw file
1// 2// Configuration.m 3// StoffiRemote 4// 5// Created by Fredrik Gadnell on 9/30/11. 6// Copyright 2011 __MyCompanyName__. All rights reserved. 7// 8 9#import "Configuration.h" 10 11 12@implementation Configuration 13 14@synthesize configurationDictionary; 15 16+ (Configuration *)configurationWithDictionary:(NSDictionary *)dictionary { 17 Configuration *_ = [[Configuration alloc] init]; 18 19 _.configurationDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionary]; 20 21 return [_ autorelease]; 22} 23 24- (NSString *)description { 25 return [configurationDictionary description]; 26} 27 28- (NSNumber *)property:(Property)property { 29 NSAssert(property >= 0 && property < NumberOfProperties, @"Unknown property"); 30 31 return [configurationDictionary objectForKey:[self keyForProperty:property]]; 32} 33 34- (void)setProperty:(Property)property toValue:(NSNumber *)number { 35 NSAssert(property >= 0 && property < NumberOfProperties, @"Unknown property"); 36 37 [configurationDictionary setObject:[self stringForValue:number 38 ofProperty:property] 39 forKey:[self keyForProperty:property]]; 40} 41 42- (NSString *)keyForProperty:(Property)property { 43 return (property == PropertyMediaState ? @"MediaState" : 44 property == PropertyVolume ? @"volume" : 45 46 @""); 47} 48 49- (NSString *)stringForValue:(NSNumber *)value ofProperty: (Property)property { 50 return (property == PropertyMediaState && [value intValue] == MediaStatePlaying ? @"playing" : 51 property == PropertyMediaState && [value intValue] == MediaStatePaused ? @"paused" : 52 property == PropertyMediaState && [value intValue] == MediaStateStopped ? @"stopped" : 53 54 property == PropertyVolume ? [NSString stringWithFormat:@"%f", [value doubleValue]] : 55 56 @""); 57} 58 59@end