Class: Redactor::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/redactor/rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reason, regex = nil, &block) ⇒ Rule

Returns a new instance of Rule.



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/redactor/rule.rb', line 5

def initialize(reason, regex = nil, &block)
  if regex && block_given?
    raise ArgumentError, 'cannot have a regex and a block'
  elsif !regex && !block_given?
    raise ArgumentError, 'must have a regex or a block'
  end

  @reason = reason
  @regex = regex
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/redactor/rule.rb', line 3

def block
  @block
end

#reasonObject (readonly)

Returns the value of attribute reason.



3
4
5
# File 'lib/redactor/rule.rb', line 3

def reason
  @reason
end

#regexObject (readonly)

Returns the value of attribute regex.



3
4
5
# File 'lib/redactor/rule.rb', line 3

def regex
  @regex
end

Instance Method Details

#extract(input) ⇒ Object



17
18
19
20
# File 'lib/redactor/rule.rb', line 17

def extract(input)
  return extract_regex(input) if regex
  return extract_block(input) if block
end