contrib/rss: extract action applied to selected elements
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 26 Jun 2015 17:59:52 +0000 (13:59 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 30 Jun 2015 16:38:01 +0000 (12:38 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/rss_downloader/src/rss_downloader.nit

index 29fdd1a..e662fac 100644 (file)
@@ -51,6 +51,13 @@ class Config
 
        # XML tag used for pattern recognition
        fun tag_title: String do return "title"
+
+       # Action to apply on each selected RSS element
+       fun act_on(element: Element)
+       do
+               var local_path = download_destination_folder.to_s / element.title
+               element.download_to(local_path)
+       end
 end
 
 # An element from an RSS feed
@@ -142,7 +149,6 @@ class Downloader
                end
 
                for element in matches do
-                       var local_path = config.download_destination_folder.to_s / element.title
                        var unique_id = element.unique_id(config)
 
                        if local_path.to_path.exists then
@@ -159,8 +165,9 @@ class Downloader
                        end
 
                        # Download element
-                       if sys.verbose then print "Fetching {element} as {local_path}"
-                       element.download_to(local_path)
+                       if sys.verbose then print "Acting on {element}"
+
+                       tool_config.act_on element
 
                        # Add `unique_id` to log
                        history.add unique_id