Class: PaperlessService::Evernote
- Inherits:
-
Object
- Object
- PaperlessService::Evernote
- Defined in:
- lib/paperless/services/evernote.rb
Instance Method Summary collapse
- #create(options) ⇒ Object
-
#initialize ⇒ Evernote
constructor
A new instance of Evernote.
Constructor Details
#initialize ⇒ Evernote
Returns a new instance of Evernote.
13 14 15 16 |
# File 'lib/paperless/services/evernote.rb', line 13 def initialize @app = app(PaperlessService::EVERNOTE) @app.activate end |
Instance Method Details
#create(options) ⇒ Object
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 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/paperless/services/evernote.rb', line 18 def create() destination = [:destination] date = [:date] from_file = [:file] title = [:title] || File.basename(from_file) = [:tags] text_ext = [:text_ext] = { :created => date } file_ext = File.extname(from_file) file_dir = File.dirname(from_file) file_name = File.basename(from_file) if file_name != title new_filename = File.join(file_dir, title + file_ext) File.rename(from_file, new_filename) from_file = new_filename end if text_ext.index file_ext.gsub!(/\./,'') puts "Adding text note into Evernote" [:with_text] = File.open(from_file, "rb") {|io| io.read} else if file_ext.match(/md$/i) # If this is a mardown file insert it into Evernote as html puts "Converting Markdown to HTML" text = File.open(from_file, "rb") {|io| io.read} [:with_html] = Markdown.new(text).to_html else # Create a note from a file and let Evernote choose how to attach the file puts "Adding note into Evernote" [:from_file] = MacTypes::FileURL.path(from_file) end end [:tags] = if .length > 0 [:notebook] = destination if destination @app.create_note() if [:delete] FileUtils.rm from_file, :force => true end @app.synchronize end |