Class: WordManager

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_twitter_egosa/word_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#excludeObject (readonly)

Returns the value of attribute exclude.



4
5
6
# File 'lib/slack_twitter_egosa/word_manager.rb', line 4

def exclude
  @exclude
end

#targetObject (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

#queryObject



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(' ').strip
end

#unmatch?(text) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/slack_twitter_egosa/word_manager.rb', line 30

def unmatch?(text)
  !match?(text)
end

#unmatch_exclude?(text) ⇒ Boolean

Returns:

  • (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

Returns:

  • (Boolean)


38
39
40
# File 'lib/slack_twitter_egosa/word_manager.rb', line 38

def unmatch_target?(text)
  !match_target?(text)
end