Sha256: 3c3b481fbdd918b013bf1ded15993ab3dc58c1fa6ff9221e0657817116d7ca14

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.6'
end

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

# require 'asearch'

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.each { |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.6 lib/re_expand.rb