• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

iSightを使ってBooklog,MediaMarkerインポート用CSVファイルを生成するアプリ


Commit MetaInfo

Revision08fa5efd9e44e2785a96bcb386ab541b81715476 (tree)
Time2011-03-04 23:26:57
Authormasakih <masakih@user...>
Commitermasakih

Log Message

[Mod] さらにビルダーパターンっぽくした。

Change Summary

Incremental Difference

--- a/BEBooklogBooksExporter.h
+++ b/BEBooklogBooksExporter.h
@@ -10,4 +10,8 @@
1010 #import "BEBooksExporter.h"
1111
1212 @interface BEBooklogBooksExporter : BEBooksExporter
13+{
14+ NSDateFormatter *registerDateFormatter;
15+ NSDateFormatter *publicateionDateFormatter;
16+}
1317 @end
--- a/BEBooklogBooksExporter.m
+++ b/BEBooklogBooksExporter.m
@@ -43,31 +43,40 @@ NSString *normalizeString(NSString *string)
4343 }
4444 return result;
4545 }
46-- (void)buildLines
46+
47+- (id)init
4748 {
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"];
7054 }
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])];
7180 }
7281
7382 @end
--- a/BEBooksExporter.h
+++ b/BEBooksExporter.h
@@ -8,6 +8,8 @@
88
99 #import <Cocoa/Cocoa.h>
1010
11+@class BEBookInformation;
12+
1113 @interface BEBooksExporter : NSObject
1214 {
1315 NSArray *books;
@@ -25,7 +27,8 @@ NSString *tagsString(NSArray *tags);
2527
2628
2729 // 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;
2932 - (NSString *)lineSeparator; // default line sparator is CRLF.
3033
3134 @end
--- a/BEBooksExporter.m
+++ b/BEBooksExporter.m
@@ -7,6 +7,7 @@
77 //
88
99 #import "BEBooksExporter.h"
10+#import "BEBookInformation.h"
1011
1112 #import "BEBooklogBooksExporter.h"
1213 #import "BEMediaMarkerBooksExporter.h"
@@ -44,6 +45,14 @@
4445 [books release];
4546 [super dealloc];
4647 }
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+}
4756 - (BOOL)exportToURL:(NSURL *)url
4857 {
4958 lines = [[NSMutableArray alloc] init];
@@ -81,7 +90,7 @@ NSString *tagsString(NSArray *tags)
8190 }
8291
8392 // for subclass
84-- (void)buildLines {}
93+- (NSString *)lineForBook:(BEBookInformation *)book { return nil; }
8594 - (NSString *)lineSeparator { return @"\r\n"; }
8695
8796 @end
--- a/BEMediaMarkerBooksExporter.h
+++ b/BEMediaMarkerBooksExporter.h
@@ -10,4 +10,8 @@
1010 #import "BEBooksExporter.h"
1111
1212 @interface BEMediaMarkerBooksExporter : BEBooksExporter
13+{
14+ NSDateFormatter *registerDateFormatter;
15+ NSDateFormatter *readDateFormatter;
16+}
1317 @end
--- a/BEMediaMarkerBooksExporter.m
+++ b/BEMediaMarkerBooksExporter.m
@@ -35,25 +35,34 @@
3535 }
3636 return result;
3737 }
38-- (void)buildLines
38+- (id)init
3939 {
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"];
5645 }
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])];
5766 }
5867
5968 @end
--- a/BEMediaMarkerImportFormatExporter.m
+++ b/BEMediaMarkerImportFormatExporter.m
@@ -11,14 +11,10 @@
1111
1212
1313 @implementation BEMediaMarkerImportFormatExporter
14-- (void)buildLines
14+- (NSString *)lineForBook:(BEBookInformation *)book
1515 {
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)];
2319 }
2420 @end