Class: Simple2ch::Thread
- Inherits:
-
Object
- Object
- Simple2ch::Thread
- Defined in:
- lib/simple2ch/thread.rb
Instance Attribute Summary collapse
-
#thread_key ⇒ String
readonly
スレッドキー(Unix time).
-
#url ⇒ Bbs2chUrlValidator::UrlInfo
readonly
URL.
Class Method Summary collapse
-
.parse(board_url, thread_data) ⇒ Simple2ch::Thread
板オブジェクトとsubject.txtの1行データを渡すとスレオブジェクトを返す.
Instance Method Summary collapse
-
#initialize(url, title: nil) ⇒ Thread
constructor
A new instance of Thread.
-
#kako_log? ⇒ Boolean
過去ログかどうかを返す.
-
#received_anchors ⇒ Hash
全てのレスに対し、あるレスへのアンカーが書き込まれているレス番号のハッシュを返す.
-
#responses(num_of_responses = nil) ⇒ Object
(also: #response)
Datを解析して、レスを返す.
-
#title ⇒ String
タイトルを返す.
-
#type_of_2ch ⇒ Symbol
2chタイプ名の取得.
Constructor Details
#initialize(url, title: nil) ⇒ Thread
Returns a new instance of Thread.
10 11 12 13 14 15 16 17 18 |
# File 'lib/simple2ch/thread.rb', line 10 def initialize(url, title: nil) @title = title @url = if url.instance_of?(Bbs2chUrlValidator::UrlInfo) url else Bbs2chUrlValidator::URL.parse(url) end raise NotA2chThreadUrlError.new "url: #{url}, title: #{title}" if !@url || @url.thread_key.nil? end |
Instance Attribute Details
#thread_key ⇒ String (readonly)
Returns スレッドキー(Unix time).
4 5 6 |
# File 'lib/simple2ch/thread.rb', line 4 def thread_key @thread_key end |
#url ⇒ Bbs2chUrlValidator::UrlInfo (readonly)
Returns URL.
6 7 8 |
# File 'lib/simple2ch/thread.rb', line 6 def url @url end |
Class Method Details
.parse(board_url, thread_data) ⇒ Simple2ch::Thread
板オブジェクトとsubject.txtの1行データを渡すとスレオブジェクトを返す
24 25 26 27 28 29 30 31 |
# File 'lib/simple2ch/thread.rb', line 24 def self.parse(board_url, thread_data) thread_data.match(/(\d{10})\.dat<>(.+) \((\d+)\)/) do |m| thread_key = m[1] title = m[2].force_encoding('utf-8').chomp thread_url = Simple2ch.generate_url(:thread, board_url, thread_key: thread_key) self.new(thread_url, title: title) end end |
Instance Method Details
#kako_log? ⇒ Boolean
過去ログかどうかを返す
51 52 53 54 |
# File 'lib/simple2ch/thread.rb', line 51 def kako_log? fetch_dat if @is_kako_log.nil? @is_kako_log end |
#received_anchors ⇒ Hash
全てのレスに対し、あるレスへのアンカーが書き込まれているレス番号のハッシュを返す
58 59 60 |
# File 'lib/simple2ch/thread.rb', line 58 def received_anchors @received_anchors ||= calc_received_anchors end |
#responses(num_of_responses = nil) ⇒ Object Also known as: response
Datを解析して、レスを返す
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/simple2ch/thread.rb', line 35 def responses(num_of_responses = nil) fetch_dat if @responses.nil? case num_of_responses when Array raise 'Blank array was given.' if num_of_responses.empty? @responses.find_all { |r| num_of_responses.index(r.res_num) } when Fixnum @responses.find { |r| r.res_num == num_of_responses } when NilClass @responses end end |
#title ⇒ String
タイトルを返す
85 86 87 88 |
# File 'lib/simple2ch/thread.rb', line 85 def title fetch_dat unless @title @title end |
#type_of_2ch ⇒ Symbol
2chタイプ名の取得
64 65 66 |
# File 'lib/simple2ch/thread.rb', line 64 def type_of_2ch Simple2ch.type_of_2ch(@url.to_s) end |