Class: Douban::Miniblog

Inherits:
Object
  • Object
show all
Includes:
Equal
Defined in:
lib/douban/miniblog.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Equal

#==

Constructor Details

#initialize(atom) ⇒ Miniblog

Returns a new instance of Miniblog.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/douban/miniblog.rb', line 26

def initialize(atom)
  doc = case atom
    when REXML::Document then atom.root
    when REXML::Element then atom
    else REXML::Document.new(atom).root
  end
  title=REXML::XPath.first(doc,"./title")
  @title=title.text if title
  published=REXML::XPath.first(doc,"./published")
  @published=published.text if published
  REXML::XPath.each(doc,"./link") do |link|
    @link||={}
    @link[link.attributes['rel']]=link.attributes['href']
  end
  id=REXML::XPath.first(doc,"./id")
  @id=id.text if id
  REXML::XPath.each(doc,"./db:attribute") do |attr|
    @attribute||={}
    @attribute[attr.attributes['name']]=attr.text
  end
  category=REXML::XPath.first(doc,"./category")
  if category
    @category={}
    @category['term']=category.attributes['term']
    @category['scheme']=category.attributes['scheme']
  end
  content=REXML::XPath.first(doc,"./content")
  @content=content.text if content
  author=REXML::XPath.first(doc,"./author")
  @author=Author.new(author.to_s) if author
end

Class Method Details

.attr_namesObject



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/douban/miniblog.rb', line 10

def attr_names
  [
    :id,
    :title,
    :category,
    :published,
    :link,
    :content,
    :attribute,
    :author
  ]
end

Instance Method Details

#miniblog_idObject



58
59
60
# File 'lib/douban/miniblog.rb', line 58

def miniblog_id
  /\/(\d+)$/.match(@id)[1].to_i rescue nil
end