lib/bbiff/bbs_reader.rb in bbiff-0.1.3 vs lib/bbiff/bbs_reader.rb in bbiff-0.2.0

- old
+ new

@@ -18,11 +18,11 @@ def 設定 応答 = Net::HTTP.start(@設定URL.host, @設定URL.port) { |http| http.get(@設定URL.path) } r = 応答.body - return r.force_encoding("EUC-JP").encode("UTF-8") + return 設定をパーズする(r.force_encoding("EUC-JP").encode("UTF-8")) end def スレ一覧 応答 = Net::HTTP.start(@スレ一覧URL.host, @スレ一覧URL.port) { |http| http.get(@スレ一覧URL.path) @@ -50,25 +50,41 @@ fail FormatError unless line =~ /^(\d+)\.cgi,([^(]+)\((\d+)\)$/ id, title, last = $1.to_i, $2, $3.to_i Thread.new(self, id, title, last) end end + + private + + def 設定をパーズする(文字列) + 文字列.each_line.map { |line| + line.chomp.split(/=/, 2) + }.to_h + end end class Post - attr_reader :no, :name, :mail, :date, :body + attr_reader :no, :name, :mail, :body def self.from_line(line) no, name, mail, date, body, = line.split('<>') Post.new(no, name, mail, date, body) end def initialize(no, name, mail, date, body) @no = no.to_i @name = name @mail = mail - @date = str2time(date) + @date = date @body = body + end + + def date + str2time(@date) + end + + def to_s + [no, name, mail, @date, body].join('<>') end private def str2time(str)