/core/externals/update-engine/externals/gdata-objectivec-client/Source/Elements/GDataMoney.m

http://macfuse.googlecode.com/ · Objective C · 70 lines · 35 code · 16 blank · 19 comment · 2 complexity · 8517f7b7e152bd09bd255b23a41c22a1 MD5 · raw file

  1. /* Copyright (c) 2008 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. //
  16. // GDataMoney.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_FINANCE_SERVICE || GDATA_INCLUDE_BOOKS_SERVICE
  19. #import "GDataMoney.h"
  20. static NSString* const kAmountAttr = @"amount";
  21. static NSString* const kCurrencyCodeAttr = @"currencyCode";
  22. @implementation GDataMoney
  23. // money element, as in
  24. // <gd:money amount="10" currencyCode="USD"/>
  25. + (NSString *)extensionElementURI { return kGDataNamespaceGData; }
  26. + (NSString *)extensionElementPrefix { return kGDataNamespaceGDataPrefix; }
  27. + (NSString *)extensionElementLocalName { return @"money"; }
  28. + (GDataMoney *)moneyWithAmount:(NSNumber *)amount
  29. currencyCode:(NSString *)currencyCode {
  30. GDataMoney *obj = [self object];
  31. [obj setAmount:amount];
  32. [obj setCurrencyCode:currencyCode];
  33. return obj;
  34. }
  35. - (void)addParseDeclarations {
  36. NSArray *attrs = [NSArray arrayWithObjects:
  37. kAmountAttr, kCurrencyCodeAttr, nil];
  38. [self addLocalAttributeDeclarations:attrs];
  39. }
  40. #pragma mark -
  41. - (NSDecimalNumber *)amount {
  42. return [self decimalNumberForAttribute:kAmountAttr];
  43. }
  44. - (void)setAmount:(NSNumber *)num {
  45. [self setStringValue:[num stringValue] forAttribute:kAmountAttr];
  46. }
  47. - (NSString *)currencyCode {
  48. return [self stringValueForAttribute:kCurrencyCodeAttr];
  49. }
  50. - (void)setCurrencyCode:(NSString *)str {
  51. [self setStringValue:str forAttribute:kCurrencyCodeAttr];
  52. }
  53. @end
  54. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_FINANCE_SERVICE || GDATA_INCLUDE_BOOKS_SERVICE