Module: CatchNotes::FinderMethods::ClassMethods
- Defined in:
- lib/catch_notes/module/finder_methods.rb
Instance Method Summary collapse
-
#all ⇒ Object
Returns all notes in the user’s catch.com account.
-
#find(id) ⇒ Object
Returns the note with the given
id. -
#find!(id) ⇒ Object
Returns the note with the given
id. -
#find_all_by_tag(tag_name) ⇒ Object
Returns all notes that contain the given
tag_name. -
#find_all_by_tag!(tag_name) ⇒ Object
Returns all notes that contain the given
tag_name. - #find_by_tag(tag_name) ⇒ Object
- #find_by_tag!(tag_name) ⇒ Object
- #first ⇒ Object
- #last ⇒ Object
- #tags ⇒ Object
Instance Method Details
#all ⇒ Object
Returns all notes in the user’s catch.com account
Example
MyNoteClass.all
9 10 11 12 |
# File 'lib/catch_notes/module/finder_methods.rb', line 9 def all res = get "/notes" build_note_array( res.parsed_response['notes'] ) if send(:ok?, res) end |
#find(id) ⇒ Object
Returns the note with the given id. Will return nil if the note doesn’t exist.
Parameters
-
id- The id of the note to find
Example
my_note = MyNoteClass.find(1234)
36 37 38 39 40 |
# File 'lib/catch_notes/module/finder_methods.rb', line 36 def find(id) find!(id) rescue CatchNotes::NotFound nil end |
#find!(id) ⇒ Object
Returns the note with the given id. Will raise a CatchNotes::NotFound exception if the note doesn’t exist.
Parameters
-
id- The id of the note to find
Example
my_note = MyNoteClass.find!(1234)
23 24 25 26 |
# File 'lib/catch_notes/module/finder_methods.rb', line 23 def find!(id) res = get "/notes/#{id}" send(:build_from_hash,res.parsed_response['notes'].first ) if send(:ok?,res) end |
#find_all_by_tag(tag_name) ⇒ Object
Returns all notes that contain the given tag_name. Will return an empty array if nothing is found, and returns nil if something goes wrong.
Parameters
-
tag_name- Then name of the tag to search for.
Example
notes_about_blah = MyNoteClass.find_all_by_tag('blah')
65 66 67 68 69 |
# File 'lib/catch_notes/module/finder_methods.rb', line 65 def find_all_by_tag( tag_name ) find_all_by_tag!(tag_name) rescue [] end |
#find_all_by_tag!(tag_name) ⇒ Object
Returns all notes that contain the given tag_name. Will return an empty array if nothing is found, and raises an exception if something goes wrong.
Parameters
-
tag_name- Then name of the tag to search for.
Example
notes_about_blah = MyNoteClass.find_all_by_tag!('blah')
51 52 53 54 |
# File 'lib/catch_notes/module/finder_methods.rb', line 51 def find_all_by_tag!( tag_name ) res = get "/search?q=%23#{tag_name}" build_note_array( res.parsed_response['notes'] ) if send(:ok?, res) end |
#find_by_tag(tag_name) ⇒ Object
75 76 77 78 79 |
# File 'lib/catch_notes/module/finder_methods.rb', line 75 def find_by_tag( tag_name ) find_all_by_tag!(tag_name).first rescue nil end |
#find_by_tag!(tag_name) ⇒ Object
71 72 73 |
# File 'lib/catch_notes/module/finder_methods.rb', line 71 def find_by_tag!( tag_name ) find_all_by_tag!(tag_name).first end |
#first ⇒ Object
81 82 83 |
# File 'lib/catch_notes/module/finder_methods.rb', line 81 def first all.first end |
#last ⇒ Object
85 86 87 |
# File 'lib/catch_notes/module/finder_methods.rb', line 85 def last all.last end |
#tags ⇒ Object
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/catch_notes/module/finder_methods.rb', line 89 def res = get "/tags" if send(:ok?, res) res.parsed_response['tags'].inject({}) do |hash, t| hash[t['name']] = Tagging.new t, self #hash[t['name'].to_sym] = Tagging.new t, self hash end end end |