/Mobile/iPhone/StoffiRemote/StoffiRemote/Configuration.m

http://yet-another-music-application.googlecode.com/ · 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. #import "Configuration.h"
  9. @implementation Configuration
  10. @synthesize configurationDictionary;
  11. + (Configuration *)configurationWithDictionary:(NSDictionary *)dictionary {
  12. Configuration *_ = [[Configuration alloc] init];
  13. _.configurationDictionary = [NSMutableDictionary dictionaryWithDictionary:dictionary];
  14. return [_ autorelease];
  15. }
  16. - (NSString *)description {
  17. return [configurationDictionary description];
  18. }
  19. - (NSNumber *)property:(Property)property {
  20. NSAssert(property >= 0 && property < NumberOfProperties, @"Unknown property");
  21. return [configurationDictionary objectForKey:[self keyForProperty:property]];
  22. }
  23. - (void)setProperty:(Property)property toValue:(NSNumber *)number {
  24. NSAssert(property >= 0 && property < NumberOfProperties, @"Unknown property");
  25. [configurationDictionary setObject:[self stringForValue:number
  26. ofProperty:property]
  27. forKey:[self keyForProperty:property]];
  28. }
  29. - (NSString *)keyForProperty:(Property)property {
  30. return (property == PropertyMediaState ? @"MediaState" :
  31. property == PropertyVolume ? @"volume" :
  32. @"");
  33. }
  34. - (NSString *)stringForValue:(NSNumber *)value ofProperty: (Property)property {
  35. return (property == PropertyMediaState && [value intValue] == MediaStatePlaying ? @"playing" :
  36. property == PropertyMediaState && [value intValue] == MediaStatePaused ? @"paused" :
  37. property == PropertyMediaState && [value intValue] == MediaStateStopped ? @"stopped" :
  38. property == PropertyVolume ? [NSString stringWithFormat:@"%f", [value doubleValue]] :
  39. @"");
  40. }
  41. @end