Sha256: 009255654256f2d9bc6cbf75bb38da1a72625dfebf75e76b637b4c2e87731145

Contents?: true

Size: 449 Bytes

Versions: 2

Compression:

Stored size: 449 Bytes

Contents

module RegXing
  class Generator
    attr_accessor :regex

    def initialize(regex)
      @regex = RegXing::Regex.new(regex)
    end

    def generate!
      str   = ""

      regex.split.each do |el|
        str << compile(el.first) * el.last
      end

      str
    end

    private

    def compile(el)
      if expr = RegXing::Regex.matchers.find {|exp, val| el.match(exp) }
        expr.last
      else
        el
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
regxing-0.1.0 lib/regxing/generator.rb
regxing-0.1.0.beta lib/regxing/generator.rb