Created
January 15, 2013 03:04
-
-
Save fedegl/4535690 to your computer and use it in GitHub Desktop.
Descrifalo!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FindReplacer < AbstractModifier | |
attr_reader :regexp, :replacement_rules | |
def initialize(original_value, replacement_rules={}) | |
@original_value = original_value | |
@replacement_rules = replacement_rules | |
end | |
def modify | |
values = original_value.map do |value| | |
replaced = nil | |
replacement_rules.each do |regexp, substitute_value| | |
replaced = value.gsub!(regexp, substitute_value) | |
end | |
replaced.present? ? value : nil | |
end.compact | |
values | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment