Class: Bbs::Shitaraba::Thread

Inherits:
ThreadBase show all
Defined in:
lib/bbiff/bbs_reader.rb

Overview

したらばスレッド

Instance Attribute Summary

Attributes inherited from ThreadBase

#board, #id, #last, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ThreadBase

#dat_url

Constructor Details

#initialize(board, id, title, last = 1) ⇒ Thread

Returns a new instance of Thread.



271
272
273
# File 'lib/bbiff/bbs_reader.rb', line 271

def initialize(board, id, title, last = 1)
  super
end

Class Method Details

.from_line(line, board) ⇒ Object



262
263
264
265
266
267
268
# File 'lib/bbiff/bbs_reader.rb', line 262

def from_line(line, board)
  unless line =~ /^(\d+)\.cgi,(.+?)\((\d+)\)$/
    fail 'スレ一覧のフォーマットが変です'
  end
  id, title, last = $1.to_i, $2, $3.to_i
  Thread.send(:new, board, id, title, last)
end

.from_url(url) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
# File 'lib/bbiff/bbs_reader.rb', line 250

def from_url(url)
  if url.to_s =~ SHITARABA_THREAD_URL_PATTERN
    category, board_num, thread_num = $1, $2.to_i, $3.to_i
    board = Board.send(:new, category, board_num)
    thread = board.thread(thread_num)
    raise 'no such thread' if thread.nil?
    return thread
  else
    return nil
  end
end

Instance Method Details

#posts(range) ⇒ Object



275
276
277
278
279
280
281
282
# File 'lib/bbiff/bbs_reader.rb', line 275

def posts(range)
  fail ArgumentError unless range.is_a? Range
  dat_for_range(range).each_line.map do |line|
    post = create_post(line.chomp)
    @last = [post.no, last].max
    post
  end
end