Class: PaperlessService::DevonThinkPro
- Inherits:
-
Object
- Object
- PaperlessService::DevonThinkPro
- Defined in:
- lib/paperless/services/devonthinkpro.rb
Instance Method Summary collapse
- #create(options) ⇒ Object
-
#initialize ⇒ DevonThinkPro
constructor
A new instance of DevonThinkPro.
Constructor Details
#initialize ⇒ DevonThinkPro
Returns a new instance of DevonThinkPro.
12 13 14 15 |
# File 'lib/paperless/services/devonthinkpro.rb', line 12 def initialize @app = app(PaperlessService::DEVONTHINKPRO) @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 51 |
# File 'lib/paperless/services/devonthinkpro.rb', line 17 def create() destination = [:destination] date = [:date] from_file = [:file] title = [:title] || File.basename(from_file) = [:tags].collect!{|x| x="'#{x}'"} # Add quotes around each tag in case there is a space time = Time.new(date.year, date.month, date.day) FileUtils.touch from_file, :mtime => time if .length > 0 # Add open meta tags to file system("#{OPENMETA} -p '#{from_file}' -a #{.join(' ')}") end # Extract the database and folder name from the destination matches = destination.match(/(.+)::(.+)/) dt_database = matches[1] dt_folder = matches[2] unless dt_folder && dt_database raise "Unable to determine database and folder for DevonThinkPro: #{destination}" end db_conn = @app.open_database(dt_database) app("System Events").processes[PaperlessService::DEVONTHINKPRO].visible.set(false) group = @app.create_location(dt_folder, {:in => db_conn}) @app.import(from_file, {:to => group, :name => title} ) if [:delete] FileUtils.rm from_file, :force => true end end |