Class: Douban::Collection

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

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Equal

#==

Constructor Details

#initialize(atom) ⇒ Collection



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
57
58
59
60
61
62
# File 'lib/douban/collection.rb', line 29

def initialize(atom)
  doc = case atom
    when REXML::Document then atom.root
    when REXML::Element then atom
    else REXML::Document.new(atom).root
  end
  subject=REXML::XPath.first(doc,"./db:subject")
  @subject=Subject.new(subject) if subject
  author=REXML::XPath.first(doc,"./author")
  @author=Author.new(author.to_s) if author
  title=REXML::XPath.first(doc,"./title")
  @title=title.text if !title.nil?
  updated=REXML::XPath.first(doc,"./updated")
  @updated=updated.text if updated
  @summary = REXML::XPath.first(doc, "./summary/text()").to_s
  @status = REXML::XPath.first(doc, "./db:status/text()").to_s
  @link = Hash.new
  REXML::XPath.each(doc, "./link") do |e|
    @link[e.attributes["rel"]] = e.attributes["href"]
  end
  id=REXML::XPath.first(doc,"./id")
  @id=id.text if id
  REXML::XPath.each(doc,"./db:tag") do |tag|
    @tag||=[]
    @tag<< tag.attributes['name']
  end
  rating=REXML::XPath.first(doc,"./db:rating")
  if rating
    @rating={}
    @rating['min']=rating.attributes['min']
    @rating['value']=rating.attributes['value']
    @rating['max']=rating.attributes['max']
  end
end

Class Method Details

.attr_namesObject



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

def attr_names
  [
    :tag,
    :updated,
    :subject,
    :author,
    :title,
    :summary,
    :link,
    :id,
    :rating,
    :status
  ]
end

Instance Method Details

#collection_idObject



64
65
66
# File 'lib/douban/collection.rb', line 64

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