DRSS

Ugly RSS interface for D.
git clone git://xatko.vsos.ethz.ch/DRSS.git
Log | Files | Refs | Submodules

commit 5ee3b977cc7c5556f5b6807683af09afab2d9b73
parent bbe3f1a16098c92a9e0936bd33cbdebcdcf163df
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Mon,  3 Aug 2015 21:02:58 +0200

Advanced DateReliable feature implemented.

if date_reliability is:
· DateReliable.NO	-> The ID is searched in entries
· DateReliable.YES	-> The ID is never checked. new Entries are determined purely by date.
· DateReliable.SEMI	-> The ID is checked, if the date says the entry is new.

Diffstat:
drss/rss.d | 34+++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/drss/rss.d b/drss/rss.d @@ -36,7 +36,12 @@ abstract class DRSS(T=Entry){ private string lastUpdated; SList!(T) entries; uint new_entries=0; - bool date_is_reliable=true; + enum DateReliable{ + NO, + SEMI, //If entry is newer, check the id additionally. + YES + }; + DateReliable date_reliability=DateReliable.SEMI; immutable string url; uint max_entries=100; uint entry_count=0; @@ -47,10 +52,29 @@ abstract class DRSS(T=Entry){ this.url=url; } - bool addEntry(Entry newent){ - if(entries.empty - || (!date_is_reliable && !canFind!("a.id==b.id")(entries[], newent)) - || (date_is_reliable && newent>entries.front) ){ + private bool checkIfNewEntry(in ref T newent){ + if(entries.empty){ + return true; + } + switch(date_reliability){ + case DateReliable.NO: + return !canFind!("a.id==b.id")(entries[], newent); + break; + case DateReliable.YES: + return (newent>entries.front); + break; + case DateReliable.SEMI: + if(newent>entries.front){ + return !canFind!("a.id==b.id")(entries[], newent); + } + default: + throw new Exception("Unknonwn reliability"); + } + return false; + } + + bool addEntry(T newent){ + if(checkIfNewEntry(newent)){ entries.insertFront(newent); new_entries++; entry_count++;