Class: Despamilator::Subject::Text
- Inherits:
-
String
- Object
- String
- Despamilator::Subject::Text
- Defined in:
- lib/despamilator/subject/text.rb
Instance Method Summary collapse
- #count(pattern) ⇒ Object
-
#initialize(text) ⇒ Text
constructor
A new instance of Text.
- #remove_and_count!(pattern) ⇒ Object
- #without_uris ⇒ Object
- #words ⇒ Object
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_uris ⇒ Object
12 13 14 |
# File 'lib/despamilator/subject/text.rb', line 12 def without_uris gsub(/\b(?:https?|mailto|ftp):.+?(\s|$)/i, '') end |
#words ⇒ Object
16 17 18 |
# File 'lib/despamilator/subject/text.rb', line 16 def words split(/\W+/) end |