Class: Douban::MiniblogComments

Inherits:
Struct
  • Object
show all
Defined in:
lib/douban/miniblog_comments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MiniblogComments

Returns a new instance of MiniblogComments.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/douban/miniblog_comments.rb', line 9

def initialize(*args)
  if args.size != 1
    super(*args)
    return
  end
  
  atom = args[0]
  doc = case atom
    when REXML::Document then atom.root
    when REXML::Element then atom
    else REXML::Document.new(atom).root
  end
  self.title = REXML::XPath.first(doc, "./title/text()").to_s rescue nil
  author = REXML::XPath.first(doc, "./author")
  self.author = Author.new(author) if author
  self.comments = []
  REXML::XPath.each(doc, "./entry") do |entry|
    self.comments << MiniblogComment.new(entry)
  end
  self.page_info = PageInfo.new(doc)
end

Instance Attribute Details

#authorObject

Returns the value of attribute author

Returns:

  • (Object)

    the current value of author



8
9
10
# File 'lib/douban/miniblog_comments.rb', line 8

def author
  @author
end

#commentsObject

Returns the value of attribute comments

Returns:

  • (Object)

    the current value of comments



8
9
10
# File 'lib/douban/miniblog_comments.rb', line 8

def comments
  @comments
end

#page_infoObject

Returns the value of attribute page_info

Returns:

  • (Object)

    the current value of page_info



8
9
10
# File 'lib/douban/miniblog_comments.rb', line 8

def page_info
  @page_info
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



8
9
10
# File 'lib/douban/miniblog_comments.rb', line 8

def title
  @title
end