Class: Log4ever::Note
Constant Summary collapse
- XML_TEMPLATE_BYTE =
237
Instance Method Summary collapse
-
#addContent(text) ⇒ Object
append content.
-
#clear ⇒ Object
clear note object.
-
#content ⇒ Object
get note content text.
-
#content=(text) ⇒ Object
set new content.
-
#content_xml ⇒ Object
get note content xml object.
-
#create ⇒ Object
create note.
-
#created_at ⇒ Object
get created time.
-
#createNote ⇒ Object
create note object.
-
#get ⇒ Object
get latest note object.
-
#get! ⇒ Object
get latest note object(newest object).
-
#guid ⇒ Object
note guid.
-
#initialize(notebook) ⇒ Note
constructor
A new instance of Note.
-
#size ⇒ Object
content size.
-
#tags ⇒ Object
get tag’s guid list.
-
#tags=(tagGuids) ⇒ Object
set tags.
-
#title=(str) ⇒ Object
set new title.
-
#update ⇒ Object
update note.
-
#updateNote ⇒ Object
get note object.
Methods inherited from Evernote
#note, #notebook, #tag, #to_ascii
Constructor Details
#initialize(notebook) ⇒ Note
Returns a new instance of Note.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/log4r/evernote.rb', line 108 def initialize(notebook) return unless @params.nil? || @params.empty? @params = {} @notebook = notebook if !@notebook.kind_of? ::Evernote::EDAM::Type::Notebook raise TypeError, "Expected kind of Notebook, got #{@notebook.class}", caller elsif !@notebook.respond_to? 'guid' raise NoMethodError, "#{@notebook.class} do not has method: guid", caller end end |
Instance Method Details
#addContent(text) ⇒ Object
append content
143 144 145 146 147 |
# File 'lib/log4r/evernote.rb', line 143 def addContent(text) new_html = "<div style='font-family: Courier New'>#{text}</div>" content_xml.at('en-note').inner_html += new_html @params[:content] = @content_ = to_ascii(content_xml.to_xml) end |
#clear ⇒ Object
clear note object
169 170 171 172 173 |
# File 'lib/log4r/evernote.rb', line 169 def clear @params = {} @note = @content_ = @content_xml = nil initialize(@notebook) end |
#content ⇒ Object
get note content text
222 223 224 225 226 |
# File 'lib/log4r/evernote.rb', line 222 def content return @content_ unless @content_.nil? @note.nil? and get @content_ = !@note.nil? && !@note.guid.nil? ? @@note_store.getNoteContent(@@auth_token, @note.guid) : "" end |
#content=(text) ⇒ Object
set new content
150 151 152 153 154 155 |
# File 'lib/log4r/evernote.rb', line 150 def content=(text) @params[:content] = @content_ = to_ascii("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">\n" + "<en-note style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;\">\n" + "<div style=\"font-family: Courier New\">#{text}</div></en-note>") end |
#content_xml ⇒ Object
get note content xml object
229 230 231 232 |
# File 'lib/log4r/evernote.rb', line 229 def content_xml return @content_xml unless @content_xml.nil? @content_xml = Nokogiri::XML(content) end |
#create ⇒ Object
create note
158 159 160 161 |
# File 'lib/log4r/evernote.rb', line 158 def create @@note_store.createNote(@@auth_token, createNote) clear end |
#created_at ⇒ Object
get created time
215 216 217 218 219 |
# File 'lib/log4r/evernote.rb', line 215 def created_at time = get.created.to_s ut = time.slice(0, time.length - 3) Time.at(ut.to_f) end |
#createNote ⇒ Object
create note object
200 201 202 203 204 205 |
# File 'lib/log4r/evernote.rb', line 200 def createNote @note = ::Evernote::EDAM::Type::Note.new @note.notebookGuid = @notebook.guid @params.each{|method, value| @note.send("#{method.to_s}=", value)} @note end |
#get ⇒ Object
get latest note object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/log4r/evernote.rb', line 176 def get return @note unless @note.nil? filter = ::Evernote::EDAM::NoteStore::NoteFilter.new filter.order = ::Evernote::EDAM::Type::NoteSortOrder::CREATED filter.notebookGuid = @notebook.guid filter.timeZone = "Asia/Tokyo" filter.ascending = false # descending note_list = @@note_store.findNotes(@@auth_token, filter, 0, 1) if note_list.notes.empty? Log4r::Logger.log_internal { "Note not found at #{@notebook.guid}" } @note = ::Evernote::EDAM::Type::Note.new else @note = note_list.notes[0] end @note end |
#get! ⇒ Object
get latest note object(newest object)
194 195 196 197 |
# File 'lib/log4r/evernote.rb', line 194 def get! clear get end |
#guid ⇒ Object
note guid
125 |
# File 'lib/log4r/evernote.rb', line 125 def guid; @note.guid end |
#size ⇒ Object
content size
120 121 122 |
# File 'lib/log4r/evernote.rb', line 120 def size content.bytesize > 0 ? content.bytesize - XML_TEMPLATE_BYTE : 0 end |
#tags ⇒ Object
get tag’s guid list
133 134 135 |
# File 'lib/log4r/evernote.rb', line 133 def get.tagGuids end |
#tags=(tagGuids) ⇒ Object
set tags
138 139 140 |
# File 'lib/log4r/evernote.rb', line 138 def (tagGuids) @params[:tagGuids] = tagGuids end |
#title=(str) ⇒ Object
set new title
128 129 130 |
# File 'lib/log4r/evernote.rb', line 128 def title=(str) @params[:title] = to_ascii(str) end |
#update ⇒ Object
update note
164 165 166 |
# File 'lib/log4r/evernote.rb', line 164 def update @@note_store.updateNote(@@auth_token, updateNote) end |
#updateNote ⇒ Object
get note object
208 209 210 211 212 |
# File 'lib/log4r/evernote.rb', line 208 def updateNote @note.nil? and get @note.content = @params[:content] @note end |