Class: Nelumba::Atom::Comment
- Inherits:
-
Object
- Object
- Nelumba::Atom::Comment
- Includes:
- Atom::Xml::Parseable
- Defined in:
- lib/nelumba/atom/comment.rb
Overview
This class represents an ActivityStreams Comment object.
Constant Summary collapse
- ACTIVITY_NAMESPACE =
The XML namespace that identifies the conforming specification.
'http://activitystrea.ms/spec/1.0/'
- THREAD_NAMESPACE =
The XML namespace that identifies the conforming specification of ‘thr’ elements.
"http://purl.org/syndication/thread/1.0"
- SCHEMA_ROOT =
The XML schema that identifies the conforming schema for objects.
'http://activitystrea.ms/schema/1.0/'
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(o = {}) {|_self| ... } ⇒ Comment
constructor
A new instance of Comment.
- #to_canonical ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(o = {}) {|_self| ... } ⇒ Comment
Returns a new instance of Comment.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/nelumba/atom/comment.rb', line 35 def initialize(o = {}) o[:activity_object_type] = SCHEMA_ROOT + "comment" case o when XML::Reader o.read parse(o) when Hash o.each do |k, v| self.send("#{k.to_s}=", v) end else raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader" end yield(self) if block_given? end |
Class Method Details
.from_canonical(obj) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/nelumba/atom/comment.rb', line 58 def self.from_canonical(obj) entry_hash = obj.to_hash entry_hash.delete :text entry_hash.delete :html entry_hash[:id] = entry_hash[:uid] entry_hash.delete :uid entry_hash[:displayName] = entry_hash[:display_name] entry_hash.delete :display_name entry_hash[:thr_in_reply_to] = entry_hash[:in_reply_to].map do |t| Nelumba::Atom::Thread.new(:href => t.url, :ref => t.uid) end entry_hash.delete :in_reply_to if entry_hash[:author] entry_hash[:author] = Nelumba::Atom::Author.from_canonical(entry_hash[:author]) end node = XML::Node.new("content") node['type'] = "html" node << entry_hash[:content] xml = XML::Reader.string(node.to_s) xml.read entry_hash[:content] = ::Atom::Content.parse(xml) self.new entry_hash end |