Class: Twords::WordMatcher

Inherits:
Object
  • Object
show all
Extended by:
ConfigAccessible
Defined in:
lib/twords/word_matcher.rb

Overview

Checks if words should be counted or not

Class Method Summary collapse

Methods included from ConfigAccessible

config

Class Method Details

.hashtag?(word) ⇒ true, false

Check if a word is a hashtag.



34
35
36
37
# File 'lib/twords/word_matcher.rb', line 34

def hashtag?(word)
  return false if config.include_hashtags
  !(word =~ /#(\w+)/).nil?
end

.mention?(word) ⇒ true, false

Check if a word is a @-mention.



54
55
56
57
# File 'lib/twords/word_matcher.rb', line 54

def mention?(word)
  return false if config.include_mentions
  !(word =~ /@(\w+)/).nil?
end

.reject?(word) ⇒ true, false

Check if a word is one of the configured rejects to ignore



25
26
27
# File 'lib/twords/word_matcher.rb', line 25

def reject?(word)
  config.rejects.include?(word)
end

.should_be_skipped?(word) ⇒ true, false

Check if a word should not be counted.



16
17
18
# File 'lib/twords/word_matcher.rb', line 16

def should_be_skipped?(word)
  reject?(word) || hashtag?(word) || uri?(word) || mention?(word)
end

.uri?(word) ⇒ true, false

Check if a word is a URI. Uses URI#regexp to match URIs



44
45
46
47
# File 'lib/twords/word_matcher.rb', line 44

def uri?(word)
  return false if config.include_uris
  !(word =~ URI.regexp).nil?
end