class BBS2ch::Thread

Attributes

name[RW]
res_count[RW]
url[RW]

Public Class Methods

new(name, url, res_count) click to toggle source
# File lib/bbs2ch/thread.rb, line 5
def initialize(name, url, res_count)
  @name      = name
  @url       = url
  @res_count = res_count
  @posts     = nil
end

Public Instance Methods

load_posts() click to toggle source
# File lib/bbs2ch/thread.rb, line 18
def load_posts
  body = Connection.new(@url).response_body
  body.each_line.map { |line|
    line.chomp!
    # [名前]<>[メール]<>[日付] [ID] [BE-ID]<>[本文]<>[スレッドタイトル]
    name, email, time_and_id, body, title = line.split('<>')

    body.gsub!('<BR>', "\n")

    begin
      time = Time.parse(time_and_id)
    rescue ArgumentError
      time = nil
    end
    time_and_id.match('ID:(\S+)')
    id = $1
    time_and_id.match('BE:(\S+)')
    be = $1

    Post.new(name, email, time, id, be, body, title)
  }
end
posts() click to toggle source
# File lib/bbs2ch/thread.rb, line 14
def posts
  @posts ||= load_posts
end