PageRenderTime 32ms CodeModel.GetById 13ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

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