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

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

http://macfuse.googlecode.com/
Objective C | 113 lines | 68 code | 24 blank | 21 comment | 3 complexity | a1392ef6d0f3d4cf788a1dd0a8e9e227 MD5 | raw file
  1/* Copyright (c) 2007 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//  GDataRating.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_BOOKS_SERVICE \
 21  || GDATA_INCLUDE_CALENDAR_SERVICE || GDATA_INCLUDE_YOUTUBE_SERVICE
 22
 23#define GDATARATING_DEFINE_GLOBALS 1
 24#import "GDataRating.h"
 25
 26static NSString* const kRelAttr = @"rel";
 27static NSString* const kValueAttr = @"value";
 28static NSString* const kMaxAttr = @"max";
 29static NSString* const kMinAttr = @"min";
 30static NSString* const kAverageAttr = @"average";
 31static NSString* const kNumRatersAttr = @"numRaters";
 32
 33@implementation GDataRating
 34// rating, as in
 35//  <gd:rating rel="http://schemas.google.com/g/2005#price" value="5" min="1" max="5"/>
 36//
 37// http://code.google.com/apis/gdata/common-elements.html#gdRating
 38
 39+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 40+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 41+ (NSString *)extensionElementLocalName { return @"rating"; }
 42
 43+ (GDataRating *)ratingWithValue:(NSInteger)value
 44                             max:(NSInteger)max
 45                             min:(NSInteger)min {
 46  GDataRating *obj = [self object];
 47  [obj setValue:[NSNumber numberWithInt:(int)value]];
 48  [obj setMax:[NSNumber numberWithInt:(int)max]];
 49  [obj setMin:[NSNumber numberWithInt:(int)min]];
 50  return obj;
 51}
 52
 53- (void)addParseDeclarations {
 54  NSArray *attrs = [NSArray arrayWithObjects:
 55                    kRelAttr, kValueAttr, kMaxAttr, kMinAttr,
 56                    kAverageAttr, kNumRatersAttr, nil];
 57
 58  [self addLocalAttributeDeclarations:attrs];
 59}
 60
 61#pragma mark -
 62
 63- (NSString *)rel {
 64  return [self stringValueForAttribute:kRelAttr];
 65}
 66
 67- (void)setRel:(NSString *)str {
 68  [self setStringValue:str forAttribute:kRelAttr];
 69}
 70
 71- (NSNumber *)value {
 72  return [self intNumberForAttribute:kValueAttr];
 73}
 74
 75- (void)setValue:(NSNumber *)num {
 76  [self setStringValue:[num stringValue] forAttribute:kValueAttr];
 77}
 78
 79- (NSNumber *)max {
 80  return [self intNumberForAttribute:kMaxAttr];
 81}
 82
 83- (void)setMax:(NSNumber *)num {
 84  [self setStringValue:[num stringValue] forAttribute:kMaxAttr];
 85}
 86
 87- (NSNumber *)min {
 88  return [self intNumberForAttribute:kMinAttr];
 89}
 90
 91- (void)setMin:(NSNumber *)num {
 92  [self setStringValue:[num stringValue] forAttribute:kMinAttr];
 93}
 94
 95- (NSNumber *)average {
 96  return [self doubleNumberForAttribute:kAverageAttr];
 97}
 98
 99- (void)setAverage:(NSNumber *)num {
100  [self setStringValue:[num stringValue] forAttribute:kAverageAttr];
101}
102
103- (NSNumber *)numberOfRaters {
104  return [self intNumberForAttribute:kNumRatersAttr];
105}
106
107- (void)setNumberOfRaters:(NSNumber *)num {
108  [self setStringValue:[num stringValue] forAttribute:kNumRatersAttr];
109}
110
111@end
112
113#endif // #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_*_SERVICE