Class: Douban::Mail

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Mail

Returns a new instance of Mail.



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

def initialize(doc)
  doc=REXML::XPath.first(REXML::Document.new(doc), "//entry") unless doc.kind_of?(REXML::Element)
  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) if author
  receiver=REXML::XPath.first(doc,"./db:entity[@name='receiver']")
  @receiver=Author.new(receiver) if receiver
end

Class Method Details

.attr_namesObject



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

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