From 53c86b29f05049d77d17a35a0ca6287174431783 Mon Sep 17 00:00:00 2001 From: David Yip Date: Sun, 3 Dec 2017 21:49:55 -0600 Subject: Glitch::FilterHelper -> Glitch::KeywordMuteHelper. #234. The class helps out with keyword mutes, not just some general concept of "filtering". --- app/models/glitch/filter_helper.rb | 31 ------------------------------- app/models/glitch/keyword_mute_helper.rb | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 app/models/glitch/filter_helper.rb create mode 100644 app/models/glitch/keyword_mute_helper.rb (limited to 'app/models/glitch') diff --git a/app/models/glitch/filter_helper.rb b/app/models/glitch/filter_helper.rb deleted file mode 100644 index 11be877c1..000000000 --- a/app/models/glitch/filter_helper.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'htmlentities' - -class Glitch::FilterHelper - include ActionView::Helpers::SanitizeHelper - - attr_reader :text_matcher - attr_reader :tag_matcher - attr_reader :entity_decoder - - def initialize(receiver_id) - @text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id) - @tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id) - @entity_decoder = HTMLEntities.new - end - - def matches?(status) - matchers_match?(status) || (status.reblog? && matchers_match?(status.reblog)) - end - - private - - def matchers_match?(status) - text_matcher.matches?(prepare_text(status.text)) || - text_matcher.matches?(prepare_text(status.spoiler_text)) || - tag_matcher.matches?(status.tags) - end - - def prepare_text(text) - entity_decoder.decode(strip_tags(text)) - end -end diff --git a/app/models/glitch/keyword_mute_helper.rb b/app/models/glitch/keyword_mute_helper.rb new file mode 100644 index 000000000..1b8c64e4e --- /dev/null +++ b/app/models/glitch/keyword_mute_helper.rb @@ -0,0 +1,31 @@ +require 'htmlentities' + +class Glitch::KeywordMuteHelper + include ActionView::Helpers::SanitizeHelper + + attr_reader :text_matcher + attr_reader :tag_matcher + attr_reader :entity_decoder + + def initialize(receiver_id) + @text_matcher = Glitch::KeywordMute.text_matcher_for(receiver_id) + @tag_matcher = Glitch::KeywordMute.tag_matcher_for(receiver_id) + @entity_decoder = HTMLEntities.new + end + + def matches?(status) + matchers_match?(status) || (status.reblog? && matchers_match?(status.reblog)) + end + + private + + def matchers_match?(status) + text_matcher.matches?(prepare_text(status.text)) || + text_matcher.matches?(prepare_text(status.spoiler_text)) || + tag_matcher.matches?(status.tags) + end + + def prepare_text(text) + entity_decoder.decode(strip_tags(text)).tap { |x| puts x } + end +end -- cgit