Class: QuoteComparer
- Inherits:
-
Object
- Object
- QuoteComparer
- Defined in:
- lib/quote_comparer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(topic_id, post_number, text) ⇒ QuoteComparer
constructor
A new instance of QuoteComparer.
-
#missing? ⇒ Boolean
This algorithm is far from perfect, but it follows the Discourse philosophy of “catch the obvious cases, leave moderation for the complicated ones”.
- #modified? ⇒ Boolean
Constructor Details
#initialize(topic_id, post_number, text) ⇒ QuoteComparer
Returns a new instance of QuoteComparer.
8 9 10 11 12 13 |
# File 'lib/quote_comparer.rb', line 8 def initialize(topic_id, post_number, text) @topic_id = topic_id @post_number = post_number @text = text @parent_post = Post.where(topic_id: @topic_id, post_number: @post_number).first end |
Class Method Details
.whitespace ⇒ Object
4 5 6 |
# File 'lib/quote_comparer.rb', line 4 def self.whitespace " \t\r\n" end |
Instance Method Details
#missing? ⇒ Boolean
This algorithm is far from perfect, but it follows the Discourse philosophy of “catch the obvious cases, leave moderation for the complicated ones”
18 19 20 |
# File 'lib/quote_comparer.rb', line 18 def missing? @parent_post.blank? end |
#modified? ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/quote_comparer.rb', line 22 def modified? return true if @text.blank? if @parent_post parent_text = Nokogiri::HTML5.fragment(@parent_post.cooked).text.delete(QuoteComparer.whitespace) text = @text.delete(QuoteComparer.whitespace) !parent_text.include?(text) end end |