Class: Simple2ch::Response
- Inherits:
-
Object
- Object
- Simple2ch::Response
- Defined in:
- lib/simple2ch/response.rb
Constant Summary collapse
- KAKO_LOG_INFO =
'過去ログ ★<><>[過去ログ]<><em>■ このスレッドは過去ログ倉庫に格納されています</em><>'.freeze
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
レス番号.
Class Method Summary collapse
-
.parse(res_num, contents) ⇒ Res
Datの1行から各項目を分離して、Resオブジェクトを返す.
Instance Method Summary collapse
-
#abone? ⇒ Boolean
あぼーんレスか否か.
-
#anchors ⇒ Array<Fixnum>
アンカーを抽出する 荒らしの場合は空配列を返す.
-
#contents_text ⇒ String
レスの内容をテキスト情報で得る。 , <, >,
はそれぞれ「 」、「<」、「>」、「(改行)」に置換される。. -
#initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '') ⇒ Response
constructor
A new instance of Response.
-
#res_author_text ⇒ String
HTMLタグを取り除いた投稿者名.
Constructor Details
#initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '') ⇒ Response
Returns a new instance of Response.
24 25 26 27 28 29 30 31 |
# File 'lib/simple2ch/response.rb', line 24 def initialize(res_num, author: '', author_id: '', date: nil, mail: '', contents: '') @res_num = res_num @author = @author_id = @date = date @mail = mail @contents = contents end |
Instance Attribute Details
#author ⇒ String (readonly)
Returns 投稿者名.
6 7 8 |
# File 'lib/simple2ch/response.rb', line 6 def @author end |
#author_id ⇒ String (readonly)
Returns ID.
8 9 10 |
# File 'lib/simple2ch/response.rb', line 8 def @author_id end |
#contents ⇒ String (readonly)
Returns 内容.
14 15 16 |
# File 'lib/simple2ch/response.rb', line 14 def contents @contents end |
#date ⇒ Time (readonly)
Returns 書き込み日時.
10 11 12 |
# File 'lib/simple2ch/response.rb', line 10 def date @date end |
#mail ⇒ String (readonly)
Returns メール欄.
12 13 14 |
# File 'lib/simple2ch/response.rb', line 12 def mail @mail end |
#res_num ⇒ Fixnum (readonly)
Returns レス番号.
4 5 6 |
# File 'lib/simple2ch/response.rb', line 4 def res_num @res_num end |
Class Method Details
.parse(res_num, contents) ⇒ Res
Datの1行から各項目を分離して、Resオブジェクトを返す
38 39 40 41 42 |
# File 'lib/simple2ch/response.rb', line 38 def self.parse(res_num, contents) raise KakoLogError if contents.strip == KAKO_LOG_INFO hash = parse_dat(contents) self.new(res_num, hash) end |
Instance Method Details
#abone? ⇒ Boolean
あぼーんレスか否か
67 68 69 |
# File 'lib/simple2ch/response.rb', line 67 def abone? @date == 'あぼーん' end |
#anchors ⇒ Array<Fixnum>
アンカーを抽出する 荒らしの場合は空配列を返す
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/simple2ch/response.rb', line 46 def anchors arashi_removal_regex = /(?:\d{1,4}(?:\]*>)?(?:>|\[>,+-\]){1,2}){9}/ return [] if 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 end |
#contents_text ⇒ String
レスの内容をテキスト情報で得る。 , <, >,
はそれぞれ「 」、「<」、「>」、「(改行)」に置換される。
73 74 75 76 77 78 |
# File 'lib/simple2ch/response.rb', line 73 def contents_text require 'htmlentities' anchor_regex = /<a href="\.\.\/test\/read.cgi\/.+\/\d{10}\/\d{1,4}" target="_blank">(>>\d{1,4})<\/a>/ @htmlentities ||= HTMLEntities.new @htmlentities.decode(@contents).gsub('<br>', "\n").gsub(/<\/?b>/, '').gsub(anchor_regex, '\1') end |
#res_author_text ⇒ String
HTMLタグを取り除いた投稿者名
82 83 84 85 86 |
# File 'lib/simple2ch/response.rb', line 82 def require 'htmlentities' @htmlentities ||= HTMLEntities.new @htmlentities.decode(@author).gsub('<br>', "\n").gsub(/<\/?b>/, '') end |