Class: BlogMarks::Mark
- Inherits:
-
Object
- Object
- BlogMarks::Mark
- Defined in:
- lib/blogmarks/mark.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Mark’s author.
-
#bm_created ⇒ Object
Mark’s creation date.
-
#edit ⇒ Object
readonly
Mark’s edit.
-
#id ⇒ Object
readonly
Mark Id.
-
#link_alternate ⇒ Object
readonly
Mark’s html representation.
-
#link_image ⇒ Object
readonly
Mark’s site screenshot.
-
#link_related ⇒ Object
Mark’s url.
-
#private_tags ⇒ Object
Mark’s private tags.
-
#public_tags ⇒ Object
Mark’s public tags.
-
#published ⇒ Object
Mark’s published date.
-
#summary ⇒ Object
Mark summary.
-
#title ⇒ Object
Mark Title.
-
#updated ⇒ Object
readonly
Mark’s last update date.
Class Method Summary collapse
-
.build_from_xml_element(entry) ⇒ Object
Parse an REXML::Element corresponding to the entry.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Mark
constructor
Create a mark from params.
-
#to_xml ⇒ Object
Return an xml representation of the mark according to BlogMarks.net Specs.
Constructor Details
#initialize(params = {}) ⇒ Mark
Create a mark from params
params hash can contains any of the object vars, but :title and :link_related is mandatory
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/blogmarks/mark.rb', line 61 def initialize( params={} ) @id = params[:id] || nil @title = params[:title] || raise( ArgumentError, ":title can't be empty") @link_related = params[:link_related] || raise( ArgumentError, ":link_related can't be empty") @link_alternate = params[:link_alternate] || nil @link_image = params[:link_image] || nil @summary = params[:summary] || nil @updated = params[:updated] || nil @published = params[:published] || nil @author = params[:author] || nil @edit = params[:edit] || nil @bm_created = params[:bm_created] || nil @public_tags = params[:public_tags] || [] @private_tags = params[:private_tags] || [] end |
Instance Attribute Details
#author ⇒ Object
Mark’s author
48 49 50 |
# File 'lib/blogmarks/mark.rb', line 48 def @author end |
#bm_created ⇒ Object
Mark’s creation date
52 53 54 |
# File 'lib/blogmarks/mark.rb', line 52 def bm_created @bm_created end |
#edit ⇒ Object (readonly)
Mark’s edit
50 51 52 |
# File 'lib/blogmarks/mark.rb', line 50 def edit @edit end |
#id ⇒ Object (readonly)
Mark Id
32 33 34 |
# File 'lib/blogmarks/mark.rb', line 32 def id @id end |
#link_alternate ⇒ Object (readonly)
Mark’s html representation
40 41 42 |
# File 'lib/blogmarks/mark.rb', line 40 def link_alternate @link_alternate end |
#link_image ⇒ Object (readonly)
Mark’s site screenshot
42 43 44 |
# File 'lib/blogmarks/mark.rb', line 42 def link_image @link_image end |
#link_related ⇒ Object
Mark’s url
38 39 40 |
# File 'lib/blogmarks/mark.rb', line 38 def @link_related end |
#private_tags ⇒ Object
Mark’s private tags
56 57 58 |
# File 'lib/blogmarks/mark.rb', line 56 def @private_tags end |
#public_tags ⇒ Object
Mark’s public tags
54 55 56 |
# File 'lib/blogmarks/mark.rb', line 54 def @public_tags end |
#published ⇒ Object
Mark’s published date
46 47 48 |
# File 'lib/blogmarks/mark.rb', line 46 def published @published end |
#summary ⇒ Object
Mark summary
36 37 38 |
# File 'lib/blogmarks/mark.rb', line 36 def summary @summary end |
#title ⇒ Object
Mark Title
34 35 36 |
# File 'lib/blogmarks/mark.rb', line 34 def title @title end |
#updated ⇒ Object (readonly)
Mark’s last update date
44 45 46 |
# File 'lib/blogmarks/mark.rb', line 44 def updated @updated end |
Class Method Details
.build_from_xml_element(entry) ⇒ Object
Parse an REXML::Element corresponding to the entry
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/blogmarks/mark.rb', line 86 def build_from_xml_element( entry ) # We need a valide REXML::Element parameters :D return nil unless entry.kind_of?(REXML::Element) # Let's build the params to build a BlogMarks::Mark params = {} # Iterate over child nodes entry.each_element do |element| case element.name when 'id' params[:id] = element.text when 'title' params[:title] = element.text when 'updated' params[:updated] = Time.parse(element.text) when 'published' params[:published] = Time.parse(element.text) when 'author' params[:author] = element.elements['name'].text when 'edit' params[:edit] = URI.parse(element.text) when 'bm:created' params[:bm_created] = Time.parse(element.text) when 'summary' params[:summary] = element.text when 'link' params[:link_related] = URI.parse( element.attributes['href'] ) if element.attributes['rel'] == 'related' params[:link_alernate] = URI.parse( element.attributes['href'] ) if element.attributes['rel'] == 'alternate' params[:link_image] = URI.parse( element.attributes['href'] ) if element.attributes['rel'] == 'image' when 'category' if element.attributes['term'] == 'http://api.blogmarks.net/tags' params[:public_tags] = [] unless params.has_key?(:public_tags) params[:public_tags] << element.attributes['label'] end if element.attributes['term'] != 'http://api.blogmarks.net/tags' params[:private_tags] = [] unless params.has_key?(:private_tags) params[:private_tags] << element.attributes['label'] end end end # Create and return a new Mark constructs using params hash return Mark.new(params) end |
Instance Method Details
#to_xml ⇒ Object
Return an xml representation of the mark according to BlogMarks.net Specs
79 80 81 |
# File 'lib/blogmarks/mark.rb', line 79 def to_xml end |