Class: Gluttonberg::Content::Despamilator::Subject::Text

Inherits:
String
  • Object
show all
Defined in:
lib/gluttonberg/content/despamilator/subject/text.rb

Instance Method Summary collapse

Methods inherited from String

#sluglize

Constructor Details

#initialize(text) ⇒ Text

Returns a new instance of Text.



9
10
11
12
# File 'lib/gluttonberg/content/despamilator/subject/text.rb', line 9

def initialize text
  super text
  freeze
end

Instance Method Details

#count(pattern) ⇒ Object



22
23
24
# File 'lib/gluttonberg/content/despamilator/subject/text.rb', line 22

def count pattern
  scan(pattern).flatten.compact.length
end

#remove_and_count!(pattern) ⇒ Object



26
27
28
29
30
# File 'lib/gluttonberg/content/despamilator/subject/text.rb', line 26

def remove_and_count! pattern
  count = count(pattern)
  gsub!(pattern, '')
  count
end

#without_urisObject



14
15
16
# File 'lib/gluttonberg/content/despamilator/subject/text.rb', line 14

def without_uris
  gsub(/\b(?:https?|mailto|ftp):.+?(\s|$)/i, '')
end

#wordsObject



18
19
20
# File 'lib/gluttonberg/content/despamilator/subject/text.rb', line 18

def words
  split(/\W+/)
end