Class: WordManager
- Inherits:
-
Object
- Object
- WordManager
- Defined in:
- lib/slack_twitter_egosa/word_manager.rb
Instance Attribute Summary collapse
-
#exclude ⇒ Object
readonly
Returns the value of attribute exclude.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(words_text) ⇒ WordManager
constructor
A new instance of WordManager.
- #match?(text) ⇒ Boolean
- #match_exclude?(text) ⇒ Boolean
- #match_target?(text) ⇒ Boolean
- #query ⇒ Object
- #unmatch?(text) ⇒ Boolean
- #unmatch_exclude?(text) ⇒ Boolean
- #unmatch_target?(text) ⇒ Boolean
Constructor Details
#initialize(words_text) ⇒ WordManager
Returns a new instance of WordManager.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 6 def initialize(words_text) @target = [] @exclude = [] words_text.to_s.dup.force_encoding('utf-8').split(' ').each do |word| if word.start_with?('-') exclude << word[1..-1] else target << word end end end |
Instance Attribute Details
#exclude ⇒ Object (readonly)
Returns the value of attribute exclude.
4 5 6 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 4 def exclude @exclude end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
4 5 6 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 4 def target @target end |
Instance Method Details
#match?(text) ⇒ Boolean
26 27 28 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 26 def match?(text) match_target?(text) && unmatch_exclude?(text) end |
#match_exclude?(text) ⇒ Boolean
42 43 44 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 42 def match_exclude?(text) !exclude.empty? && (text =~ /#{exclude.join('|')}/i ? true : false) end |
#match_target?(text) ⇒ Boolean
34 35 36 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 34 def match_target?(text) !target.empty? && (text =~ /#{target.join('|')}/i ? true : false) end |
#query ⇒ Object
19 20 21 22 23 24 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 19 def query [ target.join(' OR '), exclude.map { |word| "-#{word}" }.join(' ') ].join(' ') end |
#unmatch?(text) ⇒ Boolean
30 31 32 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 30 def unmatch?(text) !match?(text) end |
#unmatch_exclude?(text) ⇒ Boolean
46 47 48 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 46 def unmatch_exclude?(text) !match_exclude?(text) end |
#unmatch_target?(text) ⇒ Boolean
38 39 40 |
# File 'lib/slack_twitter_egosa/word_manager.rb', line 38 def unmatch_target?(text) !match_target?(text) end |