Class: Gluttonberg::Content::Despamilator::Subject::Text
- Inherits:
-
String
- Object
- String
- Gluttonberg::Content::Despamilator::Subject::Text
- Defined in:
- lib/gluttonberg/content/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.
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_uris ⇒ Object
14 15 16 |
# File 'lib/gluttonberg/content/despamilator/subject/text.rb', line 14 def without_uris gsub(/\b(?:https?|mailto|ftp):.+?(\s|$)/i, '') end |
#words ⇒ Object
18 19 20 |
# File 'lib/gluttonberg/content/despamilator/subject/text.rb', line 18 def words split(/\W+/) end |