iSightを使ってBooklog,MediaMarkerインポート用CSVファイルを生成するアプリ
Revision | 08fa5efd9e44e2785a96bcb386ab541b81715476 (tree) |
---|---|
Time | 2011-03-04 23:26:57 |
Author | masakih <masakih@user...> |
Commiter | masakih |
[Mod] さらにビルダーパターンっぽくした。
@@ -10,4 +10,8 @@ | ||
10 | 10 | #import "BEBooksExporter.h" |
11 | 11 | |
12 | 12 | @interface BEBooklogBooksExporter : BEBooksExporter |
13 | +{ | |
14 | + NSDateFormatter *registerDateFormatter; | |
15 | + NSDateFormatter *publicateionDateFormatter; | |
16 | +} | |
13 | 17 | @end |
@@ -43,31 +43,40 @@ NSString *normalizeString(NSString *string) | ||
43 | 43 | } |
44 | 44 | return result; |
45 | 45 | } |
46 | -- (void)buildLines | |
46 | + | |
47 | +- (id)init | |
47 | 48 | { |
48 | - NSDateFormatter *dateFormatter01 = [[[NSDateFormatter alloc] init] autorelease]; | |
49 | - [dateFormatter01 setDateFormat:@"YYYY-MM-dd' 'HH':'mm':'ss"]; | |
50 | - NSDateFormatter *dateFormatter02 = [[[NSDateFormatter alloc] init] autorelease]; | |
51 | - [dateFormatter02 setDateFormat:@"YYYY"]; | |
52 | - for(BEBookInformation *book in books) { | |
53 | - if(book.exported) continue; | |
54 | - NSString *line = [NSString stringWithFormat: | |
55 | - @"%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@", | |
56 | - normalizeString(book.asin), | |
57 | - normalizeString(book.isbn), | |
58 | - normalizeString(book.title), | |
59 | - normalizeString(book.author), | |
60 | - normalizeString(book.manufacturer), | |
61 | - normalizeString([dateFormatter02 stringFromDate:book.publicationDate]), | |
62 | - normalizeString(@"Books"), | |
63 | - normalizeString(book.category), | |
64 | - normalizeString([book.rating stringValue]), | |
65 | - normalizeString(book.review), | |
66 | - normalizeString([self statusNameWithBook:book]), | |
67 | - normalizeString([dateFormatter01 stringFromDate:book.readDate]), | |
68 | - normalizeString([dateFormatter01 stringFromDate:book.registerDate])]; | |
69 | - [lines addObject:line]; | |
49 | + if(self = [super init]) { | |
50 | + registerDateFormatter = [[NSDateFormatter alloc] init]; | |
51 | + [registerDateFormatter setDateFormat:@"YYYY-MM-dd' 'HH':'mm':'ss"]; | |
52 | + publicateionDateFormatter = [[NSDateFormatter alloc] init]; | |
53 | + [publicateionDateFormatter setDateFormat:@"YYYY"]; | |
70 | 54 | } |
55 | + return self; | |
56 | +} | |
57 | +- (void)dealloc | |
58 | +{ | |
59 | + [registerDateFormatter release]; | |
60 | + [publicateionDateFormatter release]; | |
61 | + [super dealloc]; | |
62 | +} | |
63 | +- (NSString *)lineForBook:(BEBookInformation *)book | |
64 | +{ | |
65 | + return [NSString stringWithFormat: | |
66 | + @"%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@\t%@", | |
67 | + normalizeString(book.asin), | |
68 | + normalizeString(book.isbn), | |
69 | + normalizeString(book.title), | |
70 | + normalizeString(book.author), | |
71 | + normalizeString(book.manufacturer), | |
72 | + normalizeString([publicateionDateFormatter stringFromDate:book.publicationDate]), | |
73 | + normalizeString(@"Books"), | |
74 | + normalizeString(book.category), | |
75 | + normalizeString([book.rating stringValue]), | |
76 | + normalizeString(book.review), | |
77 | + normalizeString([self statusNameWithBook:book]), | |
78 | + normalizeString([registerDateFormatter stringFromDate:book.readDate]), | |
79 | + normalizeString([registerDateFormatter stringFromDate:book.registerDate])]; | |
71 | 80 | } |
72 | 81 | |
73 | 82 | @end |
@@ -8,6 +8,8 @@ | ||
8 | 8 | |
9 | 9 | #import <Cocoa/Cocoa.h> |
10 | 10 | |
11 | +@class BEBookInformation; | |
12 | + | |
11 | 13 | @interface BEBooksExporter : NSObject |
12 | 14 | { |
13 | 15 | NSArray *books; |
@@ -25,7 +27,8 @@ NSString *tagsString(NSArray *tags); | ||
25 | 27 | |
26 | 28 | |
27 | 29 | // for subclass |
28 | -- (void)buildLines; | |
30 | +- (void)buildLines; // send lineForBook: message for each books if needed. you can override for anothor building way. | |
31 | +- (NSString *)lineForBook:(BEBookInformation *)book; | |
29 | 32 | - (NSString *)lineSeparator; // default line sparator is CRLF. |
30 | 33 | |
31 | 34 | @end |
@@ -7,6 +7,7 @@ | ||
7 | 7 | // |
8 | 8 | |
9 | 9 | #import "BEBooksExporter.h" |
10 | +#import "BEBookInformation.h" | |
10 | 11 | |
11 | 12 | #import "BEBooklogBooksExporter.h" |
12 | 13 | #import "BEMediaMarkerBooksExporter.h" |
@@ -44,6 +45,14 @@ | ||
44 | 45 | [books release]; |
45 | 46 | [super dealloc]; |
46 | 47 | } |
48 | +- (void)buildLines | |
49 | +{ | |
50 | + for(BEBookInformation *book in books) { | |
51 | + if(book.exported) continue; | |
52 | + NSString *line = [self lineForBook:book]; | |
53 | + if(line) [lines addObject:line]; | |
54 | + } | |
55 | +} | |
47 | 56 | - (BOOL)exportToURL:(NSURL *)url |
48 | 57 | { |
49 | 58 | lines = [[NSMutableArray alloc] init]; |
@@ -81,7 +90,7 @@ NSString *tagsString(NSArray *tags) | ||
81 | 90 | } |
82 | 91 | |
83 | 92 | // for subclass |
84 | -- (void)buildLines {} | |
93 | +- (NSString *)lineForBook:(BEBookInformation *)book { return nil; } | |
85 | 94 | - (NSString *)lineSeparator { return @"\r\n"; } |
86 | 95 | |
87 | 96 | @end |
@@ -10,4 +10,8 @@ | ||
10 | 10 | #import "BEBooksExporter.h" |
11 | 11 | |
12 | 12 | @interface BEMediaMarkerBooksExporter : BEBooksExporter |
13 | +{ | |
14 | + NSDateFormatter *registerDateFormatter; | |
15 | + NSDateFormatter *readDateFormatter; | |
16 | +} | |
13 | 17 | @end |
@@ -35,25 +35,34 @@ | ||
35 | 35 | } |
36 | 36 | return result; |
37 | 37 | } |
38 | -- (void)buildLines | |
38 | +- (id)init | |
39 | 39 | { |
40 | - NSDateFormatter *dateFormatter01 = [[[NSDateFormatter alloc] init] autorelease]; | |
41 | - [dateFormatter01 setDateFormat:@"YYYY/MM/dd' 'HH':'mm"]; | |
42 | - NSDateFormatter *dateFormatter02 = [[[NSDateFormatter alloc] init] autorelease]; | |
43 | - [dateFormatter02 setDateFormat:@"YYYY/MM/dd"]; | |
44 | - for(BEBookInformation *book in books) { | |
45 | - if(book.exported) continue; | |
46 | - NSString *line = [NSString stringWithFormat:@"\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\"", | |
47 | - doubleQuoteQuotedString(book.category), | |
48 | - doubleQuoteQuotedString(book.asin), | |
49 | - doubleQuoteQuotedString([dateFormatter01 stringFromDate:book.registerDate]), | |
50 | - doubleQuoteQuotedString(tagsString(book.tags)), | |
51 | - doubleQuoteQuotedString(book.review), | |
52 | - doubleQuoteQuotedString([book.rating stringValue]), | |
53 | - doubleQuoteQuotedString([self statusNameWithBook:book]), | |
54 | - doubleQuoteQuotedString([dateFormatter02 stringFromDate:book.readDate])]; | |
55 | - [lines addObject:line]; | |
40 | + if(self = [super init]) { | |
41 | + registerDateFormatter = [[NSDateFormatter alloc] init]; | |
42 | + [registerDateFormatter setDateFormat:@"YYYY/MM/dd' 'HH':'mm"]; | |
43 | + readDateFormatter = [[NSDateFormatter alloc] init]; | |
44 | + [readDateFormatter setDateFormat:@"YYYY/MM/dd"]; | |
56 | 45 | } |
46 | + return self; | |
47 | +} | |
48 | +- (void)dealloc | |
49 | +{ | |
50 | + [registerDateFormatter release]; | |
51 | + [readDateFormatter release]; | |
52 | + [super dealloc]; | |
53 | +} | |
54 | +- (NSString *)lineForBook:(BEBookInformation *)book | |
55 | +{ | |
56 | + | |
57 | + return [NSString stringWithFormat:@"\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\",\"%@\"", | |
58 | + doubleQuoteQuotedString(book.category), | |
59 | + doubleQuoteQuotedString(book.asin), | |
60 | + doubleQuoteQuotedString([registerDateFormatter stringFromDate:book.registerDate]), | |
61 | + doubleQuoteQuotedString(tagsString(book.tags)), | |
62 | + doubleQuoteQuotedString(book.review), | |
63 | + doubleQuoteQuotedString([book.rating stringValue]), | |
64 | + doubleQuoteQuotedString([self statusNameWithBook:book]), | |
65 | + doubleQuoteQuotedString([readDateFormatter stringFromDate:book.readDate])]; | |
57 | 66 | } |
58 | 67 | |
59 | 68 | @end |
@@ -11,14 +11,10 @@ | ||
11 | 11 | |
12 | 12 | |
13 | 13 | @implementation BEMediaMarkerImportFormatExporter |
14 | -- (void)buildLines | |
14 | +- (NSString *)lineForBook:(BEBookInformation *)book | |
15 | 15 | { |
16 | - for(BEBookInformation *book in books) { | |
17 | - if(book.exported) continue; | |
18 | - NSString *line = [NSString stringWithFormat:@"\"%@\",\"%@\"", | |
19 | - doubleQuoteQuotedString(book.asin), | |
20 | - doubleQuoteQuotedString(book.review)]; | |
21 | - [lines addObject:line]; | |
22 | - } | |
16 | + return [NSString stringWithFormat:@"\"%@\",\"%@\"", | |
17 | + doubleQuoteQuotedString(book.asin), | |
18 | + doubleQuoteQuotedString(book.review)]; | |
23 | 19 | } |
24 | 20 | @end |