Class: Mixi::Community

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

Defined Under Namespace

Classes: BBS, Fetcher

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ Community

Returns a new instance of Community.



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

def initialize(id)
  @id = id
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



16
17
18
# File 'lib/mixi-community.rb', line 16

def id
  @id
end

#titleObject (readonly)

Returns the value of attribute title.



17
18
19
# File 'lib/mixi-community.rb', line 17

def title
  @title
end

Class Method Details

.read_href(elm) ⇒ Object



6
7
8
9
10
# File 'lib/mixi-community.rb', line 6

def self.read_href(elm)
  URI.parse(
     elm.attr('data-url') || elm.attr(:href)
  )
end

Instance Method Details

#fetch(fetcher) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/mixi-community.rb', line 23

def fetch(fetcher)
  page = fetcher.get(uri)
  @recent_bbses = page.search('#newCommunityTopic .contents dl dd a').map {|a|
    bbs_uri = Mixi::Community.read_href(a)
    bbs_title = a.text
    bbs_id = Hash[bbs_uri.query.split('&').map{|kv|kv.split('=')}]['id']

    BBS.new(self.id, bbs_id, title: bbs_title)
  }
end

#recent_bbsesObject



34
35
36
# File 'lib/mixi-community.rb', line 34

def recent_bbses
  @recent_bbses
end

#uriObject



19
20
21
# File 'lib/mixi-community.rb', line 19

def uri
  URI.parse("http://mixi.jp/view_community.pl?id=#{id}")
end