Class: Wikipedia::VandalismDetection::Revision
- Inherits:
-
Object
- Object
- Wikipedia::VandalismDetection::Revision
- Defined in:
- lib/wikipedia/vandalism_detection/revision.rb
Constant Summary collapse
- START_TAG =
'<revision>'.freeze
- END_TAG =
'</revision>'.freeze
- REDIRECT_PATTERN =
/#REDIRECT\s+\[\[.*?\]\]/
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#contributor_id ⇒ Object
readonly
Returns the value of attribute contributor_id.
-
#contributor_ip ⇒ Object
readonly
Returns the value of attribute contributor_ip.
-
#contributor_username ⇒ Object
Returns the value of attribute contributor_username.
-
#id ⇒ Object
Returns the value of attribute id.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#sha1 ⇒ Object
Returns the value of attribute sha1.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #anonymous_contributor? ⇒ Boolean
- #contributor ⇒ Object
- #contributor=(contributor) ⇒ Object
-
#initialize ⇒ Revision
constructor
A new instance of Revision.
- #redirect? ⇒ Boolean
-
#text ⇒ Object
Decompresses text when called.
-
#text=(text) ⇒ Object
Compresses text when set.
Constructor Details
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
12 13 14 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 12 def comment @comment end |
#contributor_id ⇒ Object (readonly)
Returns the value of attribute contributor_id.
19 20 21 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 19 def contributor_id @contributor_id end |
#contributor_ip ⇒ Object (readonly)
Returns the value of attribute contributor_ip.
19 20 21 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 19 def contributor_ip @contributor_ip end |
#contributor_username ⇒ Object
Returns the value of attribute contributor_username.
12 13 14 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 12 def contributor_username @contributor_username end |
#id ⇒ Object
Returns the value of attribute id.
12 13 14 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 12 def id @id end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
12 13 14 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 12 def parent_id @parent_id end |
#sha1 ⇒ Object
Returns the value of attribute sha1.
12 13 14 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 12 def sha1 @sha1 end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
12 13 14 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 12 def @timestamp end |
Instance Method Details
#anonymous_contributor? ⇒ Boolean
39 40 41 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 39 def anonymous_contributor? !@contributor_ip.nil? end |
#contributor ⇒ Object
35 36 37 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 35 def contributor @contributor_id || @contributor_ip end |
#contributor=(contributor) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 27 def contributor=(contributor) if ip_v4? contributor @contributor_ip = contributor else @contributor_id = contributor end end |
#redirect? ⇒ Boolean
43 44 45 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 43 def redirect? !!(text =~ REDIRECT_PATTERN) end |
#text ⇒ Object
Decompresses text when called
56 57 58 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 56 def text Text.new(Zlib::Inflate.inflate(@text).force_encoding('utf-8')) end |
#text=(text) ⇒ Object
Compresses text when set
48 49 50 51 52 53 |
# File 'lib/wikipedia/vandalism_detection/revision.rb', line 48 def text=(text) # remove invalid utf-8 byte sequences text.encode!('UTF-16', 'UTF-8', invalid: :replace, replace: '') text.encode!('UTF-8', 'UTF-16') @text = Zlib::Deflate.deflate(text) end |