Class: Evertils::Helper::Note
- Inherits:
-
Object
- Object
- Evertils::Helper::Note
- Includes:
- Singleton
- Defined in:
- lib/evertils/helpers/note.rb
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.
- #external_url_for(note) ⇒ Object
-
#find_note_by_grammar(grammar, sleep = false) ⇒ Object
alias find_by_notebook.
-
#find_note_by_notebook(notebook, sleep = false) ⇒ Object
Find a note by notebook.
-
#find_note_by_title(title, sleep = false) ⇒ Object
Find a note by note.
-
#initialize ⇒ Note
constructor
Create the Note object.
- #internal_url_for(note) ⇒ Object
-
#wait_for_by_notebook(notebook, iterations = Evertils::Base::MAX_SEARCH_SIZE) ⇒ Object
Wait for a note to exist.
-
#wait_for_by_title(title, notebook, iterations = Evertils::Base::MAX_SEARCH_SIZE) ⇒ Object
Wait for a note to exist.
- #wait_for_with_grammar(grammar, iterations = Evertils::Base::MAX_SEARCH_SIZE) ⇒ Object
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 = Formatting.new @user = @model.user_info[:user] @shard = @model.user_info[:shard] end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
6 7 8 |
# File 'lib/evertils/helpers/note.rb', line 6 def model @model end |
Instance Method Details
#create(data) ⇒ Object Also known as: create_note
Create a note
114 115 116 |
# File 'lib/evertils/helpers/note.rb', line 114 def create(data) @model.create_note(data) end |
#external_url_for(note) ⇒ Object
109 110 111 |
# File 'lib/evertils/helpers/note.rb', line 109 def external_url_for(note) "https://www.evernote.com/Home.action#n=#{note.guid}&s=#{@shard}&ses=4&sh=2&sds=5" end |
#find_note_by_grammar(grammar, sleep = false) ⇒ Object
alias find_by_notebook
96 97 98 99 |
# File 'lib/evertils/helpers/note.rb', line 96 def find_note_by_grammar(grammar, sleep = false) sleep(5) if sleep @model.find_note_contents_using_grammar(grammar) end |
#find_note_by_notebook(notebook, sleep = false) ⇒ Object
Find a note by notebook
88 89 90 91 92 93 |
# File 'lib/evertils/helpers/note.rb', line 88 def find_note_by_notebook(notebook, sleep = false) sleep(5) if sleep title = Formatting.date_templates[notebook] @model.find_note_contents(title) end |
#find_note_by_title(title, sleep = false) ⇒ Object
Find a note by note
82 83 84 85 |
# File 'lib/evertils/helpers/note.rb', line 82 def find_note_by_title(title, sleep = false) sleep(5) if sleep @model.find_note_contents(title) end |
#internal_url_for(note) ⇒ Object
103 104 105 |
# File 'lib/evertils/helpers/note.rb', line 103 def internal_url_for(note) "evernote:///view/#{@user[:id]}/#{@shard}/#{note.guid}/#{note.guid}/" end |
#wait_for_by_notebook(notebook, iterations = Evertils::Base::MAX_SEARCH_SIZE) ⇒ Object
Wait for a note to exist
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/evertils/helpers/note.rb', line 40 def wait_for_by_notebook(notebook, iterations = Evertils::Base::MAX_SEARCH_SIZE) Notify.info("Waiting for #{notebook}...") note = find_note_by_notebook(notebook) begin # didn't find it the first time? wait and try again if note.entity.nil? (1..iterations).each do |iter| Notify.info(" (#{iter}) Looking for #{notebook.downcase}") note = find_note_by_notebook(notebook, true) break unless note.entity.nil? || iter == Evertils::Base::MAX_SEARCH_SIZE end end rescue Interrupt Notify.error('Cancelled wait') end note end |
#wait_for_by_title(title, notebook, iterations = Evertils::Base::MAX_SEARCH_SIZE) ⇒ Object
Wait for a note to exist
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/evertils/helpers/note.rb', line 61 def wait_for_by_title(title, notebook, iterations = Evertils::Base::MAX_SEARCH_SIZE) Notify.info("Waiting for #{title}...") note = find_note_by_title(title) begin # didn't find it the first time? wait and try again if note.entity.nil? (1..iterations).each do |iter| Notify.info(" (#{iter}) Looking for #{notebook.downcase}") note = find_note_by_title(notebook, true) break unless note.entity.nil? || iter == Evertils::Base::MAX_SEARCH_SIZE end end rescue Interrupt Notify.error('Cancelled wait') end note end |
#wait_for_with_grammar(grammar, iterations = Evertils::Base::MAX_SEARCH_SIZE) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/evertils/helpers/note.rb', line 18 def wait_for_with_grammar(grammar, iterations = Evertils::Base::MAX_SEARCH_SIZE) Notify.info("Searching with grammar #{grammar}") note = find_note_by_grammar(grammar.to_s) begin if note.entity.nil? (1..iterations).each do |iter| grammar.[:day] -= 1 Notify.info(" (#{iter}) Looking for #{grammar}") note = find_note_by_grammar(grammar.to_s, true) break unless note.entity.nil? || iter == Evertils::Base::MAX_SEARCH_SIZE end end rescue Interrupt Notify.error('Cancelled wait') end note end |