Module: WebPurify::TextFilters

Included in:
Client
Defined in:
lib/web_purify/methods/text_filters.rb

Overview

WebPurify::TextFilters

Handles methods related to determining/filtering profane text

Instance Method Summary collapse

Instance Method Details

#check(text, options = {}) ⇒ Boolean

Check for existence of profanity

Parameters:

  • text (String)

    Text to test for profanity

  • options (Hash) (defaults to: {})

    Options hash, used to set additional parameters

Returns:

  • (Boolean)

    True if text contains profanity, false if not



13
14
15
16
17
18
19
20
# File 'lib/web_purify/methods/text_filters.rb', line 13

def check(text, options={})
  params = {
    :method => WebPurify::Constants.methods[:check],
    :text   => text
  }
  parsed = WebPurify::Request.query(text_request_base, @query_base, params.merge(options))
  return parsed[:found]=='1'
end

#check_count(text, options = {}) ⇒ Integer

Check for existence of profanity and return number of profane words found

Parameters:

  • text (String)

    Text to test for profanity

  • options (Hash) (defaults to: {})

    Options hash, used to set additional parameters

Returns:

  • (Integer)

    The number of profane words found in text



28
29
30
31
32
33
34
35
# File 'lib/web_purify/methods/text_filters.rb', line 28

def check_count(text, options={})
  params = {
    :method => WebPurify::Constants.methods[:check_count],
    :text   => text
  }
  parsed = WebPurify::Request.query(text_request_base, @query_base, params.merge(options))
  return parsed[:found].to_i
end

#replace(text, symbol, options = {}) ⇒ String

Replace any matched profanity with provided symbol

Parameters:

  • text (String)

    Text to test for profanity

  • symbol (String)

    The symbol to replace each character of matched profanity

  • options (Hash) (defaults to: {})

    Options hash, used to set additional parameters

Returns:

  • (String)

    The original text, replaced with the provided symbol



44
45
46
47
48
49
50
51
52
# File 'lib/web_purify/methods/text_filters.rb', line 44

def replace(text, symbol, options={})
  params = {
    :method        => WebPurify::Constants.methods[:replace],
    :text          => text,
    :replacesymbol => symbol
  }
  parsed = WebPurify::Request.query(text_request_base, @query_base, params.merge(options))
  return parsed[:text]
end

#return(text, options = {}) ⇒ Array

Return an array of matched profanity

Parameters:

  • text (String)

    Text to test for profanity

  • options (Hash) (defaults to: {})

    Options hash, used to set additional parameters

Returns:

  • (Array)

    The array of matched profane words



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/web_purify/methods/text_filters.rb', line 60

def return(text, options={})
  params = {
    :method => WebPurify::Constants.methods[:return],
    :text   => text
  }
  parsed = WebPurify::Request.query(text_request_base, @query_base, params.merge(options))
  if parsed[:expletive].is_a?(String)
    return [] << parsed[:expletive]
  else
    return parsed.fetch(:expletive, [])
  end
end