Class: Simple2ch::Res

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2ch/res.rb

Constant Summary

KAKO_LOG_INFO =
'過去ログ ★<><>[過去ログ]<><em>■ このスレッドは過去ログ倉庫に格納されています</em><>'

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Res) initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '')

Returns a new instance of Res

Parameters:

  • res_num (Fixnum)

    レス番号

  • author (String)

    投稿者名

  • author_id (String)

    ID

  • date (Time)

    書き込み日時

  • mail (String)

    メール欄

  • contents (String)

    内容



25
26
27
28
29
30
31
32
# File 'lib/ruby2ch/res.rb', line 25

def initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '')
  @res_num = res_num
  @author = author
  @author_id = author_id
  @date = date
  @mail = mail
  @contents = contents
end

Instance Attribute Details

- (String) author (readonly)

Returns 投稿者名

Returns:

  • (String)

    投稿者名



6
7
8
# File 'lib/ruby2ch/res.rb', line 6

def author
  @author
end

- (String) author_id (readonly)

Returns ID

Returns:

  • (String)

    ID



8
9
10
# File 'lib/ruby2ch/res.rb', line 8

def author_id
  @author_id
end

- (String) contents (readonly)

Returns 内容

Returns:

  • (String)

    内容



14
15
16
# File 'lib/ruby2ch/res.rb', line 14

def contents
  @contents
end

- (Time) date (readonly)

Returns 書き込み日時

Returns:

  • (Time)

    書き込み日時



10
11
12
# File 'lib/ruby2ch/res.rb', line 10

def date
  @date
end

- (String) mail (readonly)

Returns メール欄

Returns:

  • (String)

    メール欄



12
13
14
# File 'lib/ruby2ch/res.rb', line 12

def mail
  @mail
end

- (Fixnum) res_num (readonly)

Returns レス番号

Returns:

  • (Fixnum)

    レス番号



4
5
6
# File 'lib/ruby2ch/res.rb', line 4

def res_num
  @res_num
end

Class Method Details

+ (Res) parse(res_num, contents)

Datの1行から各項目を分離して、Resオブジェクトを返す

Parameters:

  • res_num (Fixnum)

    レス番号

  • contents (String)

    datのデータ1行

Returns:

  • (Res)

    新規Resオブジェクト

Raises:

  • (KakoLogException)

    過去ログ情報をパースしようとした際に発生



39
40
41
42
43
44
45
# File 'lib/ruby2ch/res.rb', line 39

def self.parse(res_num, contents)
  unless contents.strip == KAKO_LOG_INFO
    self.new res_num, self.parse_dat(contents)
  else
    raise KakoLogException
  end
end