2017-06-21 06:18:46 +02:00
|
|
|
//
|
|
|
|
// RSParsedArticle.m
|
2017-06-26 01:32:07 +02:00
|
|
|
// RSParser
|
2017-06-21 06:18:46 +02:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 12/6/14.
|
|
|
|
// Copyright (c) 2014 Ranchero Software LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "RSParsedArticle.h"
|
2017-06-26 01:32:07 +02:00
|
|
|
#import "RSParserInternal.h"
|
|
|
|
#import "NSString+RSParser.h"
|
2017-06-21 06:18:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
@implementation RSParsedArticle
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Init
|
|
|
|
|
|
|
|
- (instancetype)initWithFeedURL:(NSString *)feedURL {
|
|
|
|
|
|
|
|
NSParameterAssert(feedURL != nil);
|
|
|
|
|
|
|
|
self = [super init];
|
|
|
|
if (!self) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
_feedURL = feedURL;
|
|
|
|
_dateParsed = [NSDate date];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark - Accessors
|
|
|
|
|
|
|
|
- (NSString *)articleID {
|
|
|
|
|
|
|
|
if (!_articleID) {
|
|
|
|
_articleID = self.calculatedUniqueID;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _articleID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (NSString *)calculatedUniqueID {
|
|
|
|
|
|
|
|
/*guid+feedID, or a combination of properties when no guid. Then hash the result.
|
|
|
|
In general, feeds should have guids. When they don't, re-runs are very likely,
|
|
|
|
because there's no other 100% reliable way to determine identity.*/
|
|
|
|
|
|
|
|
NSMutableString *s = [NSMutableString stringWithString:@""];
|
|
|
|
|
|
|
|
NSString *datePublishedTimeStampString = nil;
|
|
|
|
if (self.datePublished) {
|
|
|
|
datePublishedTimeStampString = [NSString stringWithFormat:@"%.0f", self.datePublished.timeIntervalSince1970];
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:06:01 +02:00
|
|
|
if (!RSParserStringIsEmpty(self.guid)) {
|
2017-06-21 06:18:46 +02:00
|
|
|
[s appendString:self.guid];
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:06:01 +02:00
|
|
|
else if (!RSParserStringIsEmpty(self.link) && self.datePublished != nil) {
|
2017-06-21 06:18:46 +02:00
|
|
|
[s appendString:self.link];
|
|
|
|
[s appendString:datePublishedTimeStampString];
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:06:01 +02:00
|
|
|
else if (!RSParserStringIsEmpty(self.title) && self.datePublished != nil) {
|
2017-06-21 06:18:46 +02:00
|
|
|
[s appendString:self.title];
|
|
|
|
[s appendString:datePublishedTimeStampString];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (self.datePublished != nil) {
|
|
|
|
[s appendString:datePublishedTimeStampString];
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:06:01 +02:00
|
|
|
else if (!RSParserStringIsEmpty(self.link)) {
|
2017-06-21 06:18:46 +02:00
|
|
|
[s appendString:self.link];
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:06:01 +02:00
|
|
|
else if (!RSParserStringIsEmpty(self.title)) {
|
2017-06-21 06:18:46 +02:00
|
|
|
[s appendString:self.title];
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:06:01 +02:00
|
|
|
else if (!RSParserStringIsEmpty(self.body)) {
|
2017-06-21 06:18:46 +02:00
|
|
|
[s appendString:self.body];
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:06:01 +02:00
|
|
|
NSAssert(!RSParserStringIsEmpty(self.feedURL), nil);
|
2017-06-21 06:18:46 +02:00
|
|
|
[s appendString:self.feedURL];
|
|
|
|
|
2017-06-26 01:32:07 +02:00
|
|
|
return [s rsparser_md5Hash];
|
2017-06-21 06:18:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)calculateArticleID {
|
|
|
|
|
|
|
|
(void)self.articleID;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|