Class: Redactor::Rule
- Inherits:
-
Object
- Object
- Redactor::Rule
- Defined in:
- lib/redactor/rule.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#regex ⇒ Object
readonly
Returns the value of attribute regex.
Instance Method Summary collapse
- #extract(input) ⇒ Object
-
#initialize(reason, regex = nil, &block) ⇒ Rule
constructor
A new instance of Rule.
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
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/redactor/rule.rb', line 3 def block @block end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
3 4 5 |
# File 'lib/redactor/rule.rb', line 3 def reason @reason end |
#regex ⇒ Object (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 |