class Bbs::Shitaraba::Thread

したらばスレッド

Public Class Methods

from_line(line, board) click to toggle source
# File lib/bbiff/bbs_reader.rb, line 265
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) click to toggle source
# File lib/bbiff/bbs_reader.rb, line 253
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
new(board, id, title, last = 1) click to toggle source
Calls superclass method Bbs::ThreadBase::new
# File lib/bbiff/bbs_reader.rb, line 274
def initialize(board, id, title, last = 1)
  super
end

Public Instance Methods

posts(range, opts = {}) click to toggle source
# File lib/bbiff/bbs_reader.rb, line 278
def posts(range, opts = {})
  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

Private Instance Methods

create_post(line) click to toggle source
# File lib/bbiff/bbs_reader.rb, line 289
def create_post(line)
  no, name, mail, date, body, = line.split('<>', 6)
  Post.new(no, name, mail, date, body)
end
dat_for_range(range) click to toggle source
# File lib/bbiff/bbs_reader.rb, line 294
def dat_for_range(range)
  if range.last == Float::INFINITY
    query = "#{range.first}-"
  else
    query = "#{range.first}-#{range.last}"
  end
  url = URI(dat_url + query)
  @board.send(:download_text, url)
end