Class: Douban::Note

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Equal

#==

Constructor Details

#initialize(doc) ⇒ Note



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
# File 'lib/douban/note.rb', line 28

def initialize(doc)
  doc = REXML::Document.new(doc).root unless doc.kind_of?(REXML::Element)
  doc = doc.root if doc.kind_of?(REXML::Document)
  
  title=REXML::XPath.first(doc,"./title")
  @title=title.text if title
  published=REXML::XPath.first(doc,"./published")
  @published=published.text if published
  updated=REXML::XPath.first(doc,"./updated")
  @updated=updated.text if updated
  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
  content=REXML::XPath.first(doc,"./content")
  @content=content.text if content
  summary=REXML::XPath.first(doc,"./summary")
  @summary=summary.text if summary
  author=REXML::XPath.first(doc,"./author")
  @author=Author.new(author.to_s) if author
end

Class Method Details

.attr_namesObject



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

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

Instance Method Details

#note_idObject



56
57
58
# File 'lib/douban/note.rb', line 56

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