public
Description: Gem Document Viewer for Mac OS X
Homepage: http://www.robinlu.com/blog/goo/
Clone URL: git://github.com/robin/goo.git
goo / GemSpecs.m
100644 55 lines (47 sloc) 1.306 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// GemSpecs.m
// goo
//
// Created by Robin Lu on 8/21/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
 
#import "GemSpecs.h"
 
@interface GemSpecs (Private)
- (void)sort;
 
@end
 
@implementation GemSpecs
@synthesize gemSpecIndex;
 
- (id)init
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"gem_helper" ofType:@"rb"];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:path];
NSPipe *outPipe = [[NSPipe alloc] init];
[task setStandardOutput:outPipe];
[outPipe release];
[task launch];
 
NSData *data = [[outPipe fileHandleForReading] readDataToEndOfFile];
NSPropertyListFormat format;
NSString *error;
gemSpecIndex = [NSPropertyListSerialization propertyListFromData:data
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&error];
if (!gemSpecIndex)
NSLog(@"%@", error);
[self sort];
return self;
}
 
- (void)sort
{
NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
NSSortDescriptor *sd2 = [[NSSortDescriptor alloc] initWithKey:@"version" ascending:NO];
NSMutableArray * sda = [[NSMutableArray alloc] init];
[sda addObject:sd];
[sda addObject:sd2];
gemSpecIndex = [gemSpecIndex sortedArrayUsingDescriptors:sda];
[sda release];
[sd release];
[sd2 release];
}
@end