Sha256: 516ab9b6553639ecd5ad2b0e46097414d6a6054ab074038ab7204edd60dac839

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# -*- coding: utf-8 -*-
$:.unshift(File.dirname(__FILE__)) unless
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))

module ReExpand
  VERSION = '0.0.3'
end

require 'Generator'
require 'Node'
require 'Asearch'
require 'Scanner'

class String
  # ExpandHelp用のライブラリを利用
  def expand(filterpat=' ')
    g = ReExpand::Generator.new
    g.add(self,"\#{$1}\t\#{$2}\t\#{$3}\t\#{$4}\t\#{$5}\t\#{$6}\t\#{$7}\t\#{$8}\t\#{$9}")
    strings = []
    #if filterpat.class == Regexp && block then
    #  g.generate(' ',block)
    #  return
    if filterpat.class == String then
      m = g.generate(filterpat)
      matched = m[0].length > 0 ? m[0] : m[1].length > 0 ? m[1] : m[2]
      strings = matched.collect { |r|
        r[0]
      }
    else
      matched = g.generate(' ')[0]
      if filterpat.class == Regexp then
        matched = matched.find_all { |r|
          filterpat.match(r[0])
        }
      end
      strings = matched.collect { |r|
        r[0]
      }
    end

    if block_given? then
      matched.collect { |m|
        yield m[0], m[1].split(/\t/)
      }
    else
      strings
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
re_expand-0.0.3 lib/re_expand.rb