class Everdone::EnmlFormatter
Constants
- URL_REGEX
from: code.tutsplus.com/tutorials/8-regular-expressions-you-should-know–net-6149 match only url’s that take the form http://…, https://… but NOT <whatever>@<url> or <host>.<domain>.<tld>
Attributes
body[R]
Public Class Methods
new(config)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 14 def initialize(config) @config = config @body = "" end
Public Instance Methods
clear()
click to toggle source
# File lib/everdone/enmlformatter.rb, line 91 def clear @body = "" end
datetime(text, source_format)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 86 def datetime(text, source_format) @body = @body + self.datetime_to_string(text, source_format) return self end
datetime_to_string(text, source_format)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 82 def datetime_to_string(text, source_format) return DateTime.strptime(text, source_format).new_offset(DateTime.now.offset).strftime(@config.evernote_datetime_format) end
h1(text)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 57 def h1(text) @body = @body + "<h1>#{text}</h1>" return self end
h2(text)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 62 def h2(text) @body = @body + "<h2>#{text}</h2>" return self end
h3(text)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 67 def h3(text) @body = @body + "<h3>#{text}</h3>" return self end
link(text, url)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 77 def link(text, url) @body = @body + "<a href='#{url}'>#{text}</a>" return self end
newline()
click to toggle source
# File lib/everdone/enmlformatter.rb, line 52 def newline() @body = @body + "<br/>" return self end
rawtext(text)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 28 def rawtext(text) # Take text and do some cooking # # Escape HTML tags so Evernote doesn't freak out on them text = CGI::escapeHTML(text) # Remove newlines and insert HTML breaks (<br/>) text_lines = text.split(/\n/) text = "" text_lines.each { |line| # Find URL-looking text and turn it into a link url_match = line.match(URL_REGEX) if url_match url = url_match[1] line.gsub!(url, "<a href='#{url}'>#{url}</a>") if url end text = text + "#{line}<br/>" } # Fix up some Todoist crap: It’s -> It's text.gsub!("’", "'"); # Put it in the body @body = @body + text return self end
space()
click to toggle source
# File lib/everdone/enmlformatter.rb, line 72 def space @body = @body + " " return self end
text(text)
click to toggle source
# File lib/everdone/enmlformatter.rb, line 19 def text(text) @body = @body + text return self end
to_s()
click to toggle source
# File lib/everdone/enmlformatter.rb, line 95 def to_s ret = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ret = "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" ret += "<en-note>#{@body}</en-note>" return ret end