/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Finance/GDataMoneyElements.m

http://macfuse.googlecode.com/ · Objective C · 141 lines · 79 code · 36 blank · 26 comment · 3 complexity · c448a8caca681d81b4a565dfa102c30d 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. // GDataMoneyElements.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_FINANCE_SERVICE
  19. #import "GDataMoneyElements.h"
  20. #import "GDataEntryFinancePortfolio.h" // for namespaces
  21. // Elements containing one or more money elements as children, like
  22. //
  23. // <gf:commission>
  24. // <gd:money amount='0.0' currencyCode='USD'/>
  25. // </gf:commission>
  26. @implementation GDataCommission
  27. + (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
  28. + (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
  29. + (NSString *)extensionElementLocalName { return @"commission"; }
  30. @end
  31. @implementation GDataCostBasis
  32. + (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
  33. + (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
  34. + (NSString *)extensionElementLocalName { return @"costBasis"; }
  35. @end
  36. @implementation GDataMarketValue
  37. + (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
  38. + (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
  39. + (NSString *)extensionElementLocalName { return @"marketValue"; }
  40. @end
  41. @implementation GDataGain
  42. + (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
  43. + (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
  44. + (NSString *)extensionElementLocalName { return @"gain"; }
  45. @end
  46. @implementation GDataDaysGain
  47. + (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
  48. + (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
  49. + (NSString *)extensionElementLocalName { return @"daysGain"; }
  50. @end
  51. @implementation GDataPrice
  52. + (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
  53. + (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
  54. + (NSString *)extensionElementLocalName { return @"price"; }
  55. @end
  56. @implementation GDataMoneyElementBase
  57. + (id)moneyGroupWithMoney:(GDataMoney *)money {
  58. GDataMoneyElementBase *obj;
  59. obj = [self object];
  60. [obj addMoney:money];
  61. return obj;
  62. }
  63. - (void)addExtensionDeclarations {
  64. [super addExtensionDeclarations];
  65. // this element may contain one or more gd:money child elements
  66. [self addExtensionDeclarationForParentClass:[self class]
  67. childClass:[GDataMoney class]];
  68. }
  69. #if !GDATA_SIMPLE_DESCRIPTIONS
  70. - (NSMutableArray *)itemsForDescription {
  71. NSMutableArray *items = [super itemsForDescription];
  72. // extensions
  73. [self addToArray:items objectDescriptionIfNonNil:[self moneys] withName:@"moneys"];
  74. return items;
  75. }
  76. #endif
  77. #pragma mark -
  78. - (NSArray *)moneys {
  79. return [self objectsForExtensionClass:[GDataMoney class]];
  80. }
  81. - (void)setMoneys:(NSArray *)arr {
  82. [self setObjects:arr forExtensionClass:[GDataMoney class]];
  83. }
  84. - (void)addMoney:(GDataMoney *)obj {
  85. [self addObject:obj forExtensionClass:[GDataMoney class]];
  86. }
  87. #pragma mark Convenience accessors
  88. - (GDataMoney *)moneyWithPrimaryCurrency {
  89. // get the first listed money, which has the primary currency
  90. NSArray *moneys = [self moneys];
  91. if ([moneys count] >= 1) {
  92. return [moneys objectAtIndex:0];
  93. }
  94. return nil;
  95. }
  96. - (GDataMoney *)moneyWithSecondaryCurrency {
  97. // get the second listed currency
  98. NSArray *moneys = [self moneys];
  99. if ([moneys count] >= 2) {
  100. return [moneys objectAtIndex:1];
  101. }
  102. return nil;
  103. }
  104. @end
  105. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_FINANCE_SERVICE