Class: Bbs::Nichan::Thread

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

Overview

2ちゃんスレッド

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.



359
360
361
# File 'lib/bbiff/bbs_reader.rb', line 359

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

Class Method Details

.from_line(line, board) ⇒ Object



350
351
352
353
354
355
356
# File 'lib/bbiff/bbs_reader.rb', line 350

def from_line(line, board)
  unless line =~ /^(\d+)\.dat<>(.+?) \((\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



337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/bbiff/bbs_reader.rb', line 337

def from_url(url)
  if url.to_s =~ NICHAN_THREAD_URL_PATTERN
    board_name, thread_num = $1, $2.to_i
    uri = URI(url)
    board = Board.send(:new, uri.hostname, uri.port, board_name)
    thread = board.thread(thread_num)
    raise NotFoundError, 'no such thread' if thread.nil?
    return thread
  else
    return nil
  end
end

Instance Method Details

#posts(range) ⇒ Object



363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/bbiff/bbs_reader.rb', line 363

def posts(range)
  fail ArgumentError unless range.is_a? Range
  url = URI(dat_url)
  lines = @board.send(:download_text, url)
  ary = []
  lines.each_line.with_index(1) do |line, res_no|
    next unless range.include?(res_no)

    name, mail, date, body, title = line.chomp.split('<>', 5)
    post = Post.new(res_no.to_s, name, mail, date, body)
    ary << post
    @last = [post.no, last].max
  end
  return ary
end