package com.jscape.util.functor;

import com.jscape.util.Assert;

/**
 * @author Alex Usun
 */
public class RegexValueSubstituter
        extends UnaryFunction<String, String> {

    private String base;
    private String regex;

    /**
     * @param base  base
     * @param regex regex
     */
    public RegexValueSubstituter(String base, String regex) {
        Assert.notNull(base);
        this.base = base;

        Assert.notNull(regex);
        this.regex = regex;
    }

    /**
     * @param value values
     *
     * @return String instance
     */
    public String evaluate(String value) {
        return this.base.replaceAll(this.regex, value);
    }

}