Class: X2CH::BbsMenu

Inherits:
Object
  • Object
show all
Defined in:
lib/x2ch.rb

Constant Summary collapse

IGNORE_CATEGORIES =
['特別企画', 'チャット', 'ツール類']
IGNORE_BOARDS =
['2chプロジェクト', 'いろいろランク']

Class Method Summary collapse

Class Method Details

.downloadObject



163
164
165
# File 'lib/x2ch.rb', line 163

def self.download
  Agent.download("http://menu.2ch.sc/bbsmenu.html")
end

.parse(html) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/x2ch.rb', line 167

def self.parse(html)
  bbs = Bbs.new
  category = nil
  html.each_line{|l|
    cname = l.match(/<BR><BR><B>(.+?)<\/B><BR>/).to_a[1]
    if cname
      if IGNORE_CATEGORIES.include?(cname)
        category = nil
      else
        category = Category.new(cname)
        bbs.push(category)
      end

      next
    end

    next unless category

    b = l.match(/<A HREF=(http:\/\/.*(?:\.2ch\.sc|\.bbspink\.com|\.machi\.to)[^\s]*).*>(.+)<\/A>/).to_a
    if b[0]
      next if IGNORE_BOARDS.include?(b[2])

      board = Board.new(b[1], b[2])
      category.push(board)
    end
  }
  bbs
end