Class: GREE::Community::Thread

Inherits:
Object
  • Object
show all
Defined in:
lib/gree-community.rb

Defined Under Namespace

Classes: Comment

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#idObject (readonly)

Returns the value of attribute id.



37
38
39
# File 'lib/gree-community.rb', line 37

def id
  @id
end

#recent_commentsObject (readonly)

Returns the value of attribute recent_comments.



38
39
40
# File 'lib/gree-community.rb', line 38

def recent_comments
  @recent_comments
end

#titleObject (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
# 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').text,
      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

#uriObject



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