Class: Despamilator::Subject::Text

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

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Text

Returns a new instance of Text.



7
8
9
10
# File 'lib/despamilator/subject/text.rb', line 7

def initialize text
  super text
  freeze
end

Instance Method Details

#count(pattern) ⇒ Object



20
21
22
# File 'lib/despamilator/subject/text.rb', line 20

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

#remove_and_count!(pattern) ⇒ Object



24
25
26
27
28
# File 'lib/despamilator/subject/text.rb', line 24

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

#without_urisObject



12
13
14
# File 'lib/despamilator/subject/text.rb', line 12

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

#wordsObject



16
17
18
# File 'lib/despamilator/subject/text.rb', line 16

def words
  split(/\W+/)
end