PageRenderTime 51ms CodeModel.GetById 15ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://macfuse.googlecode.com/
Objective C | 265 lines | 168 code | 65 blank | 32 comment | 1 complexity | 26858068885fe9ba48f997a4836d3db1 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//  GDataPortfolioElements.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_FINANCE_SERVICE
 21
 22#import "GDataPortfolioElements.h"
 23#import "GDataMoneyElements.h"
 24#import "GDataEntryFinancePortfolio.h" // for namespaces
 25
 26static NSString *const kGainPercentageAttr = @"gainPercentage";
 27static NSString *const kReturn1wAttr = @"return1w";
 28static NSString *const kReturn1yAttr = @"return1y";
 29static NSString *const kReturn3mAttr = @"return3m";
 30static NSString *const kReturn3yAttr = @"return3y";
 31static NSString *const kReturn4wAttr = @"return4w";
 32static NSString *const kReturn5yAttr = @"return5y";
 33static NSString *const kReturnOverallAttr = @"returnOverall";
 34static NSString *const kReturnYTDAttr = @"returnYTD";
 35
 36// portfolio-only
 37static NSString *const kCurrencyCodeAttr = @"currencyCode";
 38
 39// position-only
 40static NSString *const kSharesAttr = @"shares";
 41
 42
 43//
 44// Portfolio subclass
 45//
 46
 47@implementation GDataPortfolioData
 48+ (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
 49+ (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
 50+ (NSString *)extensionElementLocalName { return @"portfolioData"; }
 51
 52+ (GDataPortfolioData *)portfolioData {
 53  GDataPortfolioData *obj = [self object];
 54  return obj;
 55}
 56
 57- (void)addParseDeclarations {
 58  
 59  [super addParseDeclarations];
 60  
 61  NSArray *attrs = [NSArray arrayWithObject:kCurrencyCodeAttr];
 62  
 63  [self addLocalAttributeDeclarations:attrs];
 64}
 65
 66- (NSString *)currencyCode {
 67  return [self stringValueForAttribute:kCurrencyCodeAttr];
 68}
 69
 70- (void)setCurrencyCode:(NSString *)str {
 71  [self setStringValue:str forAttribute:kCurrencyCodeAttr]; 
 72}
 73@end
 74
 75// 
 76// Position subclass
 77//
 78
 79@implementation GDataPositionData
 80+ (NSString *)extensionElementPrefix { return kGDataNamespaceFinancePrefix; }
 81+ (NSString *)extensionElementURI { return kGDataNamespaceFinance; }
 82+ (NSString *)extensionElementLocalName { return @"positionData"; }
 83
 84+ (GDataPositionData *)positionData {
 85  GDataPositionData *obj = [self object];
 86  return obj;
 87}
 88
 89- (void)addParseDeclarations {
 90    
 91  // add shares before adding the superclass's attributes so it shows
 92  // first in the description's list of attributes
 93  
 94  NSArray *attrs = [NSArray arrayWithObject:kSharesAttr];
 95  [self addLocalAttributeDeclarations:attrs];
 96  
 97  [super addParseDeclarations];
 98}
 99
100- (NSDecimalNumber *)shares {
101  return [self decimalNumberForAttribute:kSharesAttr];
102}
103
104- (void)setShares:(NSNumber *)num {
105  [self setStringValue:[num stringValue] forAttribute:kSharesAttr]; 
106}
107@end
108
109//
110// common base
111//
112@implementation GDataPortfolioBase 
113
114- (void)addExtensionDeclarations {
115
116  [super addExtensionDeclarations];
117
118  Class elementClass = [self class];
119  [self addExtensionDeclarationForParentClass:elementClass
120                                 childClasses:
121   [GDataCostBasis class],
122   [GDataDaysGain class],
123   [GDataGain class],
124   [GDataMarketValue class],
125   nil];
126}
127
128- (void)addParseDeclarations {
129  
130  NSArray *attrs = [NSArray arrayWithObjects:
131                    kGainPercentageAttr, kReturnOverallAttr, kReturnYTDAttr,
132                    kReturn1wAttr, kReturn1yAttr, kReturn3mAttr, kReturn3yAttr,
133                    kReturn4wAttr, kReturn5yAttr, nil];
134                    
135  [self addLocalAttributeDeclarations:attrs];
136}
137
138#if !GDATA_SIMPLE_DESCRIPTIONS
139- (NSMutableArray *)itemsForDescription {
140
141  static struct GDataDescriptionRecord descRecs[] = {
142    { @"costBasis", @"costBasis", kGDataDescValueLabeled },
143    { @"daysGain",  @"daysGain",  kGDataDescValueLabeled },
144    { @"gain",      @"gain",      kGDataDescValueLabeled },
145    { @"daysGain",  @"daysGain",  kGDataDescValueLabeled },
146    { nil, nil, (GDataDescRecTypes)0 }
147  };
148
149  NSMutableArray *items = [super itemsForDescription];
150  [self addDescriptionRecords:descRecs toItems:items];
151  return items;
152}
153#endif
154
155// common attributes
156
157- (NSNumber *)gainPercentage {
158  return [self doubleNumberForAttribute:kGainPercentageAttr];
159}
160
161- (void)setGainPercentage:(NSNumber *)num {
162  [self setStringValue:[num stringValue] forAttribute:kGainPercentageAttr]; 
163}
164
165- (NSDecimalNumber *)return1w {
166  return [self decimalNumberForAttribute:kReturn1wAttr];
167}
168
169- (void)setReturn1w:(NSNumber *)num {
170  [self setStringValue:[num stringValue] forAttribute:kReturn1wAttr]; 
171}
172
173- (NSDecimalNumber *)return1y {
174  return [self decimalNumberForAttribute:kReturn1yAttr];
175}
176
177- (void)setReturn1y:(NSNumber *)num {
178  [self setStringValue:[num stringValue] forAttribute:kReturn1yAttr]; 
179}
180
181- (NSDecimalNumber *)return3m {
182  return [self decimalNumberForAttribute:kReturn3mAttr];
183}
184
185- (void)setReturn3m:(NSNumber *)num {
186  [self setStringValue:[num stringValue] forAttribute:kReturn3mAttr]; 
187}
188
189- (NSDecimalNumber *)return3y {
190  return [self decimalNumberForAttribute:kReturn3yAttr];
191}
192
193- (void)setReturn3y:(NSNumber *)num {
194  [self setStringValue:[num stringValue] forAttribute:kReturn3yAttr]; 
195}
196
197- (NSDecimalNumber *)return4w {
198  return [self decimalNumberForAttribute:kReturn4wAttr];
199}
200
201- (void)setReturn4w:(NSNumber *)num {
202  [self setStringValue:[num stringValue] forAttribute:kReturn4wAttr]; 
203}
204
205- (NSDecimalNumber *)return5y {
206  return [self decimalNumberForAttribute:kReturn5yAttr];
207}
208
209- (void)setReturn5y:(NSNumber *)num {
210  [self setStringValue:[num stringValue] forAttribute:kReturn5yAttr]; 
211}
212
213- (NSDecimalNumber *)returnOverall {
214  return [self decimalNumberForAttribute:kReturnOverallAttr];
215}
216
217- (void)setReturnOverall:(NSNumber *)num {
218  [self setStringValue:[num stringValue] forAttribute:kReturnOverallAttr]; 
219}
220
221- (NSDecimalNumber *)returnYTD {
222  return [self decimalNumberForAttribute:kReturnYTDAttr];
223}
224
225- (void)setReturnYTD:(NSNumber *)num {
226  [self setStringValue:[num stringValue] forAttribute:kReturnYTDAttr]; 
227}
228
229// extensions
230
231- (GDataCostBasis *)costBasis {
232  return [self objectForExtensionClass:[GDataCostBasis class]];
233}
234
235 - (void)setCostBasis:(GDataCostBasis *)obj {
236   [self setObject:obj forExtensionClass:[GDataCostBasis class]];
237 }
238
239- (GDataGain *)gain {
240  return [self objectForExtensionClass:[GDataGain class]];
241}
242
243- (void)setGain:(GDataGain *)obj {
244  [self setObject:obj forExtensionClass:[GDataGain class]];
245}
246
247- (GDataDaysGain *)daysGain {
248  return [self objectForExtensionClass:[GDataDaysGain class]];
249}
250
251- (void)setDaysGain:(GDataDaysGain *)obj {
252  [self setObject:obj forExtensionClass:[GDataDaysGain class]];
253}
254
255- (GDataMarketValue *)marketValue {
256  return [self objectForExtensionClass:[GDataMarketValue class]];
257}
258
259- (void)setMarketValue:(GDataMarketValue *)obj {
260  [self setObject:obj forExtensionClass:[GDataMarketValue class]];
261}
262
263@end
264
265#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_FINANCE_SERVICE