Class: GREE::Community::Thread
- Inherits:
-
Object
- Object
- GREE::Community::Thread
- Defined in:
- lib/gree-community.rb
Defined Under Namespace
Classes: Comment
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#recent_comments ⇒ Object
readonly
Returns the value of attribute recent_comments.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #fetch(fetcher) ⇒ Object
-
#initialize(id, values = {}) ⇒ Thread
constructor
A new instance of Thread.
- #uri ⇒ Object
Constructor Details
#initialize(id, values = {}) ⇒ Thread
Returns a new instance of Thread.
32 33 34 35 36 |
# File 'lib/gree-community.rb', line 32 def initialize(id,values={}) @id=id @recent_comments=values[:recent_comments] @title=values[:title] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
37 38 39 |
# File 'lib/gree-community.rb', line 37 def id @id end |
#recent_comments ⇒ Object (readonly)
Returns the value of attribute recent_comments.
38 39 40 |
# File 'lib/gree-community.rb', line 38 def recent_comments @recent_comments end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
39 40 41 |
# File 'lib/gree-community.rb', line 39 def title @title end |
Instance Method Details
#fetch(fetcher) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gree-community.rb', line 45 def fetch(fetcher) page=fetcher.get(self.uri) @title = page.at('.title').text @recent_comments = page.search('.comment-list li').map{|comment| id = Integer(comment.attr(:id)) body = comment. at('.item'). children[3..-1] Comment.new( id, user_name: comment.at('.item strong a').text, user_id: comment.at('.item strong a').attr(:href).match(%r{gree\.jp/(\d+)}) ? $1 : nil, body_text: body.map{|elm| elm.name == 'br' ? "\n" : elm.text }.join('').gsub(//,''), time: Time.strptime(comment.at('.shoulder .timestamp').text, '%m/%d %H:%M'), ) } nil end |
#uri ⇒ Object
40 41 42 43 44 |
# File 'lib/gree-community.rb', line 40 def uri URI.parse( "http://gree.jp/?mode=community&act=bbs_view&thread_id=#{self.id}" ) end |