Class: Lotus::Atom::Thread

Inherits:
Object
  • Object
show all
Includes:
Atom::Xml::Parseable
Defined in:
lib/lotus/atom/thread.rb

Overview

This will parse the Thread Atom extension

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(o) ⇒ Thread

Returns a new instance of Thread.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lotus/atom/thread.rb', line 12

def initialize(o)
  case o
  when XML::Reader
    if current_node_is?(o, 'in-reply-to')
      parse(o, :once => true)
    else
      raise ArgumentError, "Thread created with node other than thr:in-reply-to: #{o.name}"
    end
  when Hash
    [:href, :ref, :type, :source].each do |attr|
      self.send("#{attr}=", o[attr])
    end
  else
    raise ArgumentError, "Don't know how to handle #{o}"
  end
end

Class Method Details

.from_canonical(obj) ⇒ Object



41
42
43
# File 'lib/lotus/atom/thread.rb', line 41

def self.from_canonical(obj)
  self.new(obj.to_hash)
end

Instance Method Details

#==(o) ⇒ Object



37
38
39
# File 'lib/lotus/atom/thread.rb', line 37

def ==(o)
  o.respond_to?(:href) && o.href == self.href
end

#infoObject



50
51
52
53
54
55
56
57
# File 'lib/lotus/atom/thread.rb', line 50

def info
  {
    :ref    => self.ref,
    :type   => self.type,
    :source => self.source,
    :href   => self.href
  }
end

#length=(v) ⇒ Object



29
30
31
# File 'lib/lotus/atom/thread.rb', line 29

def length=(v)
  @length = v.to_i
end

#to_canonicalObject



45
46
47
48
# File 'lib/lotus/atom/thread.rb', line 45

def to_canonical
  Lotus::Activity.new(:url => self.href,
                      :id  => self.ref)
end

#to_sObject



33
34
35
# File 'lib/lotus/atom/thread.rb', line 33

def to_s
  self.href
end