Class: Wikipedia::VandalismDetection::Edit
- Inherits:
-
Object
- Object
- Wikipedia::VandalismDetection::Edit
- Defined in:
- lib/wikipedia/vandalism_detection/edit.rb
Instance Attribute Summary collapse
-
#new_revision ⇒ Object
readonly
Returns the value of attribute new_revision.
-
#old_revision ⇒ Object
readonly
Returns the value of attribute old_revision.
-
#page ⇒ Object
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(old_revision, new_revision, attributes = {}) ⇒ Edit
constructor
A new instance of Edit.
-
#inserted_text ⇒ Object
Returns a Text of the words inserted in the new revision compared with the old one.
-
#inserted_words ⇒ Object
Returns an array of the words inserted in the new revision compared with the old one.
-
#removed_text ⇒ Object
Returns a Text of the words removed in the new revision compared with the old one.
-
#removed_words ⇒ Object
Returns an array of the words removed in the new revision compared with the old one.
- #serialize(*attributes) ⇒ Object
Constructor Details
#initialize(old_revision, new_revision, attributes = {}) ⇒ Edit
Returns a new instance of Edit.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 12 def initialize(old_revision, new_revision, attributes = {}) = "old revision: #{old_revision.id} | parent: #{old_revision.parent_id}, new revision: #{new_revision.id} | parent: #{new_revision.parent_id}" raise ArgumentError, "Revisions are not sequent: #{}." unless sequent?(old_revision, new_revision) @old_revision = old_revision @new_revision = new_revision @page = attributes[:page] || Page.new end |
Instance Attribute Details
#new_revision ⇒ Object (readonly)
Returns the value of attribute new_revision.
9 10 11 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 9 def new_revision @new_revision end |
#old_revision ⇒ Object (readonly)
Returns the value of attribute old_revision.
9 10 11 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 9 def old_revision @old_revision end |
#page ⇒ Object
Returns the value of attribute page.
10 11 12 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 10 def page @page end |
Instance Method Details
#inserted_text ⇒ Object
Returns a Text of the words inserted in the new revision compared with the old one.
52 53 54 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 52 def inserted_text @inserted_text ||= Text.new(inserted_words.join(' ')) end |
#inserted_words ⇒ Object
Returns an array of the words inserted in the new revision compared with the old one.
46 47 48 49 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 46 def inserted_words @diff ||= Diff.new(@old_revision.text, @new_revision.text) @inserted_words ||= @diff.inserted_words end |
#removed_text ⇒ Object
Returns a Text of the words removed in the new revision compared with the old one.
63 64 65 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 63 def removed_text @removed_text ||= Text.new(removed_words.join(' ')) end |
#removed_words ⇒ Object
Returns an array of the words removed in the new revision compared with the old one.
57 58 59 60 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 57 def removed_words @diff ||= Diff.new(@old_revision.text, @new_revision.text) @removed_words ||= @diff.removed_words end |
#serialize(*attributes) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wikipedia/vandalism_detection/edit.rb', line 23 def serialize(*attributes) old_revision_parts = [] new_revision_parts = [] attributes.each do |attr| if @old_revision.respond_to?(attr) old_revision_parts.push @old_revision.method(attr).call end end attributes.each do |attr| if @new_revision.respond_to?(attr) new_revision_parts.push @new_revision.method(attr).call end end old_revision_string = old_revision_parts.join(',') new_revision_string = new_revision_parts.join(',') "#{old_revision_string}\t#{new_revision_string}" end |