Commits

Jonathan Gilbert committed cc99814

Added support for associated files for archiving

  • Participants
  • Parent commits 002d629

Comments (0)

Files changed (5)

 Gem::Specification.new do |s|
   s.name        = 'flickrup'
-  s.version     = '1.1.4'
+  s.version     = '1.1.5'
   s.date        = '2012-12-21'
   s.summary     = "Flickr Uploader!"
   s.description = "Flickr auto uploading script"

flickrup.yml.example

   FocalLength:
     "0.0 mm": "7.5 mm"
   FocalLengthIn35mmFormat:
-    "0 mm": "7.5 mm"
+    "0 mm": "7.5 mm"
+associated_files:
+    - /JPG$/NEF/i

lib/flickrup/archiver.rb

 require "fileutils"
 
 class Archiver
+  include Logging
 
   def archive(ctx)
     archive_file_by_date(ctx.properties[:filename], ctx.properties[:archive_dir], ctx.properties[:date_taken], ctx.properties[:subdir])

lib/flickrup/ext/associated_files.rb

+class AssociatedFiles
+
+  def initialize(config, delegate, context)
+    @delegate = delegate
+    @replacements = config[:associated_files].map do |x|
+      extract_pair(x)
+    end
+  end
+
+  def archive(ctx)
+    @delegate.archive(ctx)
+    @replacements.map do |x|
+      other = ctx.properties[:filename].gsub(*x)
+      if File.exist? other
+        @delegate.archive(ctx.with_properties({:filename => other}))
+      end
+    end
+  end
+
+  private
+  def extract_pair(pair_string)
+    items = pair_string[1..-1].split(pair_string[0])
+    [Regexp.new("(?#{items[2]}:#{items[0]})"), items[1]]
+  end
+end

lib/flickrup/processor.rb

 require "flickrup/ext/machine_tags"
 require "flickrup/ext/visibility"
 require "flickrup/archiver"
+require "flickrup/ext/associated_files"
 
 class Processor
   include Logging
   end
 
   def archive_handlers
-    [TagSets]
+    [TagSets, AssociatedFiles]
   end
 
 end