Module: Evernotable::Utilities
- Included in:
- Client::Note, Command, Command::Base
- Defined in:
- lib/evernotable/utilities.rb
Instance Method Summary collapse
- #display(msg = "", new_line = true) ⇒ Object
- #encrypt_key ⇒ Object
- #error(msg) ⇒ Object
- #format_with_bang(message) ⇒ Object
- #output_with_bang(message = "", new_line = true) ⇒ Object
- #read_from_file(file) ⇒ Object
- #wrap_enml(content) ⇒ Object
- #write_to_file(file, content) ⇒ Object
Instance Method Details
#display(msg = "", new_line = true) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/evernotable/utilities.rb', line 16 def display(msg="", new_line=true) if new_line STDOUT.puts(msg) else STDOUT.print(msg) STDOUT.flush end end |
#encrypt_key ⇒ Object
42 43 44 45 |
# File 'lib/evernotable/utilities.rb', line 42 def encrypt_key config = YAML.load(File.read('lib/evernotable_config.yml')) return config["encryption"]["key"] end |
#error(msg) ⇒ Object
25 26 27 28 |
# File 'lib/evernotable/utilities.rb', line 25 def error(msg) STDERR.puts(format_with_bang(msg)) exit(1) end |
#format_with_bang(message) ⇒ Object
6 7 8 9 |
# File 'lib/evernotable/utilities.rb', line 6 def format_with_bang() return '' if .to_s.strip == "" "! " + .split("\n").join("\n ! ") end |
#output_with_bang(message = "", new_line = true) ⇒ Object
11 12 13 14 |
# File 'lib/evernotable/utilities.rb', line 11 def output_with_bang(="", new_line=true) return if .to_s.strip == "" display(format_with_bang(), new_line) end |
#read_from_file(file) ⇒ Object
38 39 40 |
# File 'lib/evernotable/utilities.rb', line 38 def read_from_file(file) File.exist?(file) ? File.read(file).decrypt(:symmetric, :password => encrypt_key) : '' end |
#wrap_enml(content) ⇒ Object
30 31 32 |
# File 'lib/evernotable/utilities.rb', line 30 def wrap_enml(content) "<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE en-note SYSTEM 'http://xml.evernote.com/pub/enml2.dtd'><en-note>#{content}</en-note>" end |
#write_to_file(file, content) ⇒ Object
34 35 36 |
# File 'lib/evernotable/utilities.rb', line 34 def write_to_file(file, content) File.open(file, 'w') {|f| f.write(content.encrypt(:symmetric, :password => encrypt_key))} end |