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.

Returns:

  • (true)

    if hashtags should not be included and word is a hashtag

  • (false)

    if all hashtags should be included or word is not 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.

Returns:

  • (true)

    if @-mentions should not be included and word is a @-mention

  • (false)

    if all @-mentions should be included or word is not 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

Returns:

  • (true)

    if word is a reject

  • (false)

    if word is not a reject



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.

Returns:

  • (true)

    if word should be skipped

  • (false)

    if word should not be skipped



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

Returns:

  • (true)

    if URIs should not be included and word is a URI

  • (false)

    if all URIs should be included or word is not a URI



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