Class: Magnolia::Mark
- Inherits:
-
Object
- Object
- Magnolia::Mark
- Defined in:
- lib/magnolia/magnolia.rb
Overview
The mark class is used to store information about each bookmark after it is found, created or updated. Each method that is not in the DONT_PROCESS constant returns and array of Mark
objects.
Instance Attribute Summary collapse
-
#a_tag ⇒ Object
readonly
Creates a link to the url of the bookmark with the title as the text.
-
#created ⇒ Object
Returns the value of attribute created.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#img_tag ⇒ Object
readonly
Creates an image tag for the screenshot image with the title as the alt text.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#private ⇒ Object
Returns the value of attribute private.
-
#rating ⇒ Object
Returns the value of attribute rating.
-
#screenshot ⇒ Object
Returns the value of attribute screenshot.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
-
#updated ⇒ Object
Returns the value of attribute updated.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.find(id) ⇒ Object
Finds a single bookmark by it’s id (short name).
-
.from_xml(xml) ⇒ Object
Converts xml into a mark.
Instance Method Summary collapse
-
#initialize ⇒ Mark
constructor
A new instance of Mark.
-
#save ⇒ Object
This method allows working with bookmarks much like ActiveRecord.
Constructor Details
#initialize ⇒ Mark
Returns a new instance of Mark.
374 375 376 |
# File 'lib/magnolia/magnolia.rb', line 374 def initialize @tags = [] end |
Instance Attribute Details
#a_tag ⇒ Object (readonly)
Creates a link to the url of the bookmark with the title as the text
388 389 390 |
# File 'lib/magnolia/magnolia.rb', line 388 def a_tag @a_tag end |
#created ⇒ Object
Returns the value of attribute created.
379 380 381 |
# File 'lib/magnolia/magnolia.rb', line 379 def created @created end |
#description ⇒ Object
Returns the value of attribute description.
377 378 379 |
# File 'lib/magnolia/magnolia.rb', line 377 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
377 378 379 |
# File 'lib/magnolia/magnolia.rb', line 377 def id @id end |
#img_tag ⇒ Object (readonly)
Creates an image tag for the screenshot image with the title as the alt text
383 384 385 |
# File 'lib/magnolia/magnolia.rb', line 383 def img_tag @img_tag end |
#owner ⇒ Object
Returns the value of attribute owner.
379 380 381 |
# File 'lib/magnolia/magnolia.rb', line 379 def owner @owner end |
#private ⇒ Object
Returns the value of attribute private.
378 379 380 |
# File 'lib/magnolia/magnolia.rb', line 378 def private @private end |
#rating ⇒ Object
Returns the value of attribute rating.
378 379 380 |
# File 'lib/magnolia/magnolia.rb', line 378 def @rating end |
#screenshot ⇒ Object
Returns the value of attribute screenshot.
378 379 380 |
# File 'lib/magnolia/magnolia.rb', line 378 def screenshot @screenshot end |
#tags ⇒ Object
Returns the value of attribute tags.
379 380 381 |
# File 'lib/magnolia/magnolia.rb', line 379 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
377 378 379 |
# File 'lib/magnolia/magnolia.rb', line 377 def title @title end |
#updated ⇒ Object
Returns the value of attribute updated.
379 380 381 |
# File 'lib/magnolia/magnolia.rb', line 379 def updated @updated end |
#url ⇒ Object
Returns the value of attribute url.
377 378 379 |
# File 'lib/magnolia/magnolia.rb', line 377 def url @url end |
Class Method Details
.find(id) ⇒ Object
Finds a single bookmark by it’s id (short name). If not found raises a Magnolia::RequestError
448 449 450 451 |
# File 'lib/magnolia/magnolia.rb', line 448 def find(id) marks = Magnolia.get(:id =>id) marks[0] end |
.from_xml(xml) ⇒ Object
Converts xml into a mark
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/magnolia/magnolia.rb', line 454 def from_xml(xml) mark = Mark.new() mark.title = xml.elements['title'].text mark.url = xml.elements['url'].text mark.description = xml.elements['description'].text mark.screenshot = xml.elements['screenshot'].text mark.id = xml.attributes['id'] mark. = xml.attributes['rating'] mark.private = xml.attributes['private'] mark.created = xml.attributes['created'] mark.updated = xml.attributes['updated'] mark.owner = xml.attributes['owner'] REXML::XPath.each(xml, 'tags/tag') do |tag| mark. << tag.attributes['name'] end mark end |
Instance Method Details
#save ⇒ Object
This method allows working with bookmarks much like ActiveRecord.
Examples
mark = Magnolia::Mark.new
mark.title = 'Addicted To New'
mark.url = 'http://addictedtonew.com/'
mark. = ['john nunemaker', 'me'] # you can also use comma-seperated list mark.tags = 'john nunemaker, me'
mark.save
puts mark.id # this is the id of the newly created bookmark
You can also use it to update bookmarks like so:
mark = Magnolia::Mark.find(:id => 'someshortname')
mark.title = 'Addicted To New by John Nunemaker'
mark.save
408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/magnolia/magnolia.rb', line 408 def save if self.id == nil # create a new bookmark mark = to_h marks = Magnolia.add(mark) self.id = marks[0].id else # update an existing bookmark mark = to_h marks = Magnolia.update(mark) end end |