Class: Simple2ch::Res
- Inherits:
-
Object
- Object
- Simple2ch::Res
- Defined in:
- lib/simple2ch/res.rb
Constant Summary collapse
- KAKO_LOG_INFO =
'過去ログ ★<><>[過去ログ]<><em>■ このスレッドは過去ログ倉庫に格納されています</em><>'
Instance Attribute Summary collapse
-
#author ⇒ String
readonly
投稿者名.
-
#author_id ⇒ String
readonly
ID.
-
#contents ⇒ String
readonly
内容.
-
#date ⇒ Time
readonly
書き込み日時.
-
#mail ⇒ String
readonly
メール欄.
-
#res_num ⇒ Fixnum
readonly
レス番号.
- #thre ⇒ Object writeonly
Class Method Summary collapse
-
.parse(res_num, contents, thre = nil) ⇒ Res
Datの1行から各項目を分離して、Resオブジェクトを返す.
Instance Method Summary collapse
-
#anchors ⇒ Array<Fixnum>
アンカーを抽出する 荒らしの場合は空配列を返す.
-
#initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '', thre: nil) ⇒ Res
constructor
A new instance of Res.
-
#received_anchors ⇒ Object
自レスへのアンカーが書き込まれているレス番号を返す.
Constructor Details
#initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '', thre: nil) ⇒ Res
Returns a new instance of Res.
27 28 29 30 31 32 33 34 35 |
# File 'lib/simple2ch/res.rb', line 27 def initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '', thre: nil) @res_num = res_num @author = @author_id = @date = date @mail = mail @contents = contents @thre = thre end |
Instance Attribute Details
#author ⇒ String (readonly)
Returns 投稿者名.
6 7 8 |
# File 'lib/simple2ch/res.rb', line 6 def @author end |
#author_id ⇒ String (readonly)
Returns ID.
8 9 10 |
# File 'lib/simple2ch/res.rb', line 8 def @author_id end |
#contents ⇒ String (readonly)
Returns 内容.
14 15 16 |
# File 'lib/simple2ch/res.rb', line 14 def contents @contents end |
#date ⇒ Time (readonly)
Returns 書き込み日時.
10 11 12 |
# File 'lib/simple2ch/res.rb', line 10 def date @date end |
#mail ⇒ String (readonly)
Returns メール欄.
12 13 14 |
# File 'lib/simple2ch/res.rb', line 12 def mail @mail end |
#res_num ⇒ Fixnum (readonly)
Returns レス番号.
4 5 6 |
# File 'lib/simple2ch/res.rb', line 4 def res_num @res_num end |
#thre=(value) ⇒ Object (writeonly)
16 17 18 |
# File 'lib/simple2ch/res.rb', line 16 def thre=(value) @thre = value end |
Class Method Details
.parse(res_num, contents, thre = nil) ⇒ Res
Datの1行から各項目を分離して、Resオブジェクトを返す
42 43 44 45 46 47 48 49 50 |
# File 'lib/simple2ch/res.rb', line 42 def self.parse(res_num, contents, thre=nil) unless contents.strip == KAKO_LOG_INFO hash = parse_dat(contents) hash[:thre] = thre if thre return self.new(res_num, hash) else raise KakoLogException end end |
Instance Method Details
#anchors ⇒ Array<Fixnum>
アンカーを抽出する 荒らしの場合は空配列を返す
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/simple2ch/res.rb', line 54 def anchors arashi_removal_regex = /(?:\d{1,4}(?:\]*>)?(?:>|\[>,+-\]){1,2}){9}/ unless self.contents =~ arashi_removal_regex splitter_regex = '[,、, ]' digit_regex = '(?:\d|[0-9])+' hyphen_regex = '[−ーー\-〜~〜]' extracted = self.contents.scan />((?:#{digit_regex}(?:#{splitter_regex}|#{hyphen_regex})*)+)/ anchors = extracted.flatten.to_s.gsub(/[\"\[\]]/,'').split(/#{splitter_regex}/) anchors.delete('') anchors.map! do |a| if a =~ /(#{digit_regex})#{hyphen_regex}(#{digit_regex})/ (Range.new parseInt($1), parseInt($2)).to_a else parseInt(a) end end anchors.flatten.uniq.sort else [] end end |
#received_anchors ⇒ Object
自レスへのアンカーが書き込まれているレス番号を返す
78 79 80 81 82 |
# File 'lib/simple2ch/res.rb', line 78 def received_anchors thre = get_thre received_anchors = thre.received_anchors received_anchors.fetch(@res_num, []) end |