Class: Simple2ch::Thre

Inherits:
Object
  • Object
show all
Defined in:
lib/simple2ch/thre.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(board, thread_key, title: '', num_of_response: '') ⇒ Thre

Returns a new instance of Thre.

Parameters:

  • board (Board)

    スレッドが属する板情報

  • thread_key (String)

    スレッドキー

  • title (String) (defaults to: '')

    スレッド名

  • num_of_response (Fixnum) (defaults to: '')

    総書き込み数



16
17
18
19
20
21
22
23
24
# File 'lib/simple2ch/thre.rb', line 16

def initialize(board, thread_key, title: '', num_of_response: '')
  @board = board
  @thread_key = thread_key
  @title = title
  @num_of_response = num_of_response
  @reses = nil
  @f_kako_log = nil
  @received_anchors = nil
end

Instance Attribute Details

#boardBoard (readonly)

Returns 属する板.

Returns:

  • (Board)

    属する板



10
11
12
# File 'lib/simple2ch/thre.rb', line 10

def board
  @board
end

#num_of_responseFixnum (readonly)

Returns 返信の数.

Returns:

  • (Fixnum)

    返信の数



8
9
10
# File 'lib/simple2ch/thre.rb', line 8

def num_of_response
  @num_of_response
end

#thread_keyString (readonly)

Returns スレッドキー(Unix time).

Returns:

  • (String)

    スレッドキー(Unix time)



6
7
8
# File 'lib/simple2ch/thre.rb', line 6

def thread_key
  @thread_key
end

#titleString (readonly)

Returns スレッドの名前.

Returns:

  • (String)

    スレッドの名前



4
5
6
# File 'lib/simple2ch/thre.rb', line 4

def title
  @title
end

Class Method Details

.parse(board, thread_data) ⇒ Thre

板オブジェクトとsubject.txtの1行データを渡すとスレオブジェクトを返す

Parameters:

  • board (Board)

    スレッドが属する板情報

  • thread_data (String)

    0000000000.dat<>スレッドタイトル (レス数)

Returns:



30
31
32
33
34
35
36
37
# File 'lib/simple2ch/thre.rb', line 30

def self.parse(board, thread_data)
  thread_data =~ /(\d{10})\.dat<>(.+) \((\d+)\)/
  hash = {}
  thread_key = $1
  hash[:title] = $2
  hash[:num_of_response] = $3.to_i
  self.new board, thread_key, hash
end

Instance Method Details

#kako_log?Boolean

過去ログかどうかを返す

Returns:

  • (Boolean)

    過去ログか否か



55
56
57
58
# File 'lib/simple2ch/thre.rb', line 55

def kako_log?
  fetch_dat if @f_kako_log.nil?
  @f_kako_log
end

#received_anchorsHash

全てのレスに対し、あるレスへのアンカーが書き込まれているレス番号のハッシュを返す

Returns:

  • (Hash)

    { res_num<Fixnum> => res_nums<Array<Fixnum>> } レス番号のハッシュ



62
63
64
# File 'lib/simple2ch/thre.rb', line 62

def received_anchors
  @received_anchors ||= calc_received_anchors
end

#reses(num_of_reses = nil) ⇒ Array<Res>

Datを解析して、レスを返す

Parameters:

  • num_of_reses (Array<Fixnum>) (defaults to: nil)

    取得したいレス番号

Returns:

  • (Array<Res>)

    レスの配列



42
43
44
45
46
47
48
49
50
51
# File 'lib/simple2ch/thre.rb', line 42

def reses(num_of_reses=nil)
  fetch_dat unless @reses
  if num_of_reses && num_of_reses.size > 0
    @reses.find_all{|r|
      num_of_reses.index(r.res_num)
    }
  else
    @reses
  end
end