Class: GREE::Community

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

Defined Under Namespace

Classes: Fetcher, Thread

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Community

Returns a new instance of Community.



8
9
10
# File 'lib/gree-community.rb', line 8

def initialize id
  @id=id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/gree-community.rb', line 11

def id
  @id
end

#recent_threadsObject (readonly)

Returns the value of attribute recent_threads.



12
13
14
# File 'lib/gree-community.rb', line 12

def recent_threads
  @recent_threads
end

Instance Method Details

#fetch(fetcher) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gree-community.rb', line 18

def fetch(fetcher)
  page=fetcher.get(recent_threads_uri)
  @recent_threads=page.search('.feed .item').map{|item|
    thread_uri = item.at('.head a').attr(:href)
    thread_uri =~ /&thread_id=(\d+)/
    thread_id = Integer($1)
    thread_title = item.at('.head a strong').text
    Thread.new(
      thread_id,
      title: thread_title,
    )
  }
end

#recent_threads_uriObject



13
14
15
16
17
# File 'lib/gree-community.rb', line 13

def recent_threads_uri
  URI.parse(
    "http://gree.jp/?mode=community&act=bbs_list&community_id=#{id}"
  )
end