Class: Douban::Recommendation
- Inherits:
-
Object
- Object
- Douban::Recommendation
- Includes:
- Equal
- Defined in:
- lib/douban/recommendation.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(entry = "") ⇒ Recommendation
constructor
A new instance of Recommendation.
- #recommendation_id ⇒ Object
Methods included from Equal
Constructor Details
#initialize(entry = "") ⇒ Recommendation
Returns a new instance of Recommendation.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/douban/recommendation.rb', line 19 def initialize(entry="") if entry.kind_of? REXML::Element doc = entry else doc = REXML::Document.new(entry) end @id = REXML::XPath.first(doc, ".//id/text()").to_s @title = REXML::XPath.first(doc, ".//title/text()").to_s = REXML::XPath.first(doc, ".//author") = Author.new(.to_s) if @published = REXML::XPath.first(doc, ".//published/text()").to_s @content = REXML::XPath.first(doc, ".//content/text()").to_s @content_type = REXML::XPath.first(doc, ".//content/@type").value() rescue nil @category = REXML::XPath.first(doc, ".//db:attribute[@name='category']/text()").to_s @comment = REXML::XPath.first(doc, ".//db:attribute[@name='comment']/text()").to_s @comments_count = REXML::XPath.first(doc, ".//db:attribute[@name='comment_count']/text()").to_i rescue 0 end |
Class Method Details
.attr_names ⇒ Object
10 11 12 |
# File 'lib/douban/recommendation.rb', line 10 def attr_names @@attr_names ||= %w(id title author published content content_type category comment comments_count).map {|x| x.to_sym} end |
Instance Method Details
#recommendation_id ⇒ Object
43 44 45 |
# File 'lib/douban/recommendation.rb', line 43 def recommendation_id %r{/(\d+)$}.match(@id)[1].to_i rescue nil end |