Class: Simple2ch::Res
- Inherits:
-
Object
- Object
- Simple2ch::Res
- Defined in:
- lib/simple2ch/res.rb
Constant Summary
- KAKO_LOG_INFO =
'過去ログ ★<><>[過去ログ]<><em>■ このスレッドは過去ログ倉庫に格納されています</em><>'
Instance Attribute Summary (collapse)
-
- (String) author
readonly
投稿者名.
-
- (String) author_id
readonly
ID.
-
- (String) contents
readonly
内容.
-
- (Time) date
readonly
書き込み日時.
-
- (String) mail
readonly
メール欄.
-
- (Fixnum) res_num
readonly
レス番号.
- - (Object) thre writeonly
Class Method Summary (collapse)
-
+ (Res) parse(res_num, contents, thre = nil)
Datの1行から各項目を分離して、Resオブジェクトを返す.
Instance Method Summary (collapse)
-
- (Array<Fixnum>) anchors
アンカーを抽出する 荒らしの場合は空配列を返す.
-
- (Res) initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '', thre: nil)
constructor
A new instance of Res.
-
- (Object) received_anchors
自レスへのアンカーが書き込まれているレス番号を返す.
Constructor Details
- (Res) initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '', thre: nil)
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
- (String) author (readonly)
Returns 投稿者名
6 7 8 |
# File 'lib/simple2ch/res.rb', line 6 def @author end |
- (String) author_id (readonly)
Returns ID
8 9 10 |
# File 'lib/simple2ch/res.rb', line 8 def @author_id end |
- (String) contents (readonly)
Returns 内容
14 15 16 |
# File 'lib/simple2ch/res.rb', line 14 def contents @contents end |
- (Time) date (readonly)
Returns 書き込み日時
10 11 12 |
# File 'lib/simple2ch/res.rb', line 10 def date @date end |
- (String) mail (readonly)
Returns メール欄
12 13 14 |
# File 'lib/simple2ch/res.rb', line 12 def mail @mail end |
- (Fixnum) res_num (readonly)
Returns レス番号
4 5 6 |
# File 'lib/simple2ch/res.rb', line 4 def res_num @res_num end |
- (Object) thre=(value) (writeonly)
16 17 18 |
# File 'lib/simple2ch/res.rb', line 16 def thre=(value) @thre = value end |
Class Method Details
+ (Res) parse(res_num, contents, thre = nil)
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
- (Array<Fixnum>) anchors
アンカーを抽出する 荒らしの場合は空配列を返す
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 |
- (Object) received_anchors
自レスへのアンカーが書き込まれているレス番号を返す
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 |