Class: Evertils::Helper::Note
- Inherits:
-
Object
- Object
- Evertils::Helper::Note
- Defined in:
- lib/evertils/helpers/note.rb
Constant Summary collapse
- MAX_SEARCH_SIZE =
21
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#create(data) ⇒ Object
(also: #create_note)
Create a note.
-
#find_note(notebook, sleep = false) ⇒ Object
(also: #find_by_notebook)
Find a note.
-
#initialize ⇒ Note
constructor
Create the Note object.
- #internal_url_for(note) ⇒ Object
-
#wait_for(notebook) ⇒ Object
Wait for a note to exist.
Constructor Details
#initialize ⇒ Note
Create the Note object
9 10 11 12 13 14 |
# File 'lib/evertils/helpers/note.rb', line 9 def initialize @model = Evertils::Common::Query::Simple.new @format = Evertils::Helper.load('Formatting') @user = @model.user_info[:user] @shard = @model.user_info[:shard] end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/evertils/helpers/note.rb', line 4 def model @model end |
Instance Method Details
#create(data) ⇒ Object Also known as: create_note
Create a note
48 49 50 |
# File 'lib/evertils/helpers/note.rb', line 48 def create(data) @model.create_note(data) end |
#find_note(notebook, sleep = false) ⇒ Object Also known as: find_by_notebook
Find a note
34 35 36 37 38 |
# File 'lib/evertils/helpers/note.rb', line 34 def find_note(notebook, sleep = false) sleep(5) if sleep title = @format.date_templates[notebook] @model.find_note_contents(title) end |
#internal_url_for(note) ⇒ Object
43 44 45 |
# File 'lib/evertils/helpers/note.rb', line 43 def internal_url_for(note) "evernote:///view/#{@user[:id]}/#{@shard}/#{note.guid}/#{note.guid}/" end |
#wait_for(notebook) ⇒ Object
Wait for a note to exist
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/evertils/helpers/note.rb', line 17 def wait_for(notebook) Notify.info("Waiting for #{notebook}...") note = find_note(notebook) # didn't find it the first time? wait and try again if note.entity.nil? (1..MAX_SEARCH_SIZE).each do |iter| Notify.info(" (#{iter}) #{notebook}") note = find_note(notebook, true) break unless note.entity.nil? || iter == MAX_SEARCH_SIZE end end note end |