Class: PaperlessService::Finder
- Inherits:
-
Object
- Object
- PaperlessService::Finder
- Defined in:
- lib/paperless/services/finder.rb
Constant Summary collapse
- NO_MOVE =
'<nomove>'
Instance Method Summary collapse
- #create(options) ⇒ Object
-
#initialize ⇒ Finder
constructor
A new instance of Finder.
Constructor Details
#initialize ⇒ Finder
Returns a new instance of Finder.
12 13 14 15 |
# File 'lib/paperless/services/finder.rb', line 12 def initialize @app = app(PaperlessService::FINDER) @app.activate end |
Instance Method Details
#create(options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/paperless/services/finder.rb', line 17 def create() destination = [:destination] date = [:date] from_file = [:file] title = [:title] || File.basename(from_file, File.extname(from_file)) = [:tags].collect!{|x| x="'#{x}'"} # Add quotes around each tag in case there is a space if destination == NO_MOVE || destination == File.dirname(from_file) new_filename = File.join(File.dirname(from_file), title + File.extname(from_file)) puts "New filename (1): #{new_filename}" else FileUtils.mkdir_p destination unless File.exists?(destination) new_filename = File.join(destination, title + File.extname(from_file)) puts "New filename (2): #{new_filename}" end puts "Copying File..." FileUtils.cp from_file, new_filename, :verbose => true time = Time.new(date.year, date.month, date.day) puts "Modifying the time of the file to be #{time.to_s}" FileUtils.touch new_filename, {:mtime => time} if .length > 0 # Add open meta tags to file puts "Tagging file" system("#{OPENMETA} -p '#{new_filename}' -a #{.join(' ')}") end if [:delete] && from_file != new_filename puts "Removing original file" FileUtils.rm from_file, :force => true, :verbose => true end end |