4/08/2008

Ruby's Regular Express

3 or 4 days ago, I try one program with ruby.

It's contents that transform words matched keyword in regular expression into other words.

Keywords are ProjectName , author and date.

Next codes are this program.


#!/usr/bin/ruby
class TextValue

    # class's member
    TABLE = {
    "ProjectName"=>"AAA",
    "author"=>"bulldog",
    "date"=>Time.now.strftime("%Y-%m-%d")}

end

begin

    TextValue::TABLE["ProjectName"] = ARGV[1]
    # open the file
    tmp = open(ARGV[1])
    while line = tmp.gets()

      if /\$(\w*)\$/ =~ line then
        print line.gsub(/\$(\w*)\$/, TextValue::TABLE[$1])

      else
        print line

      end
      end

    tmp.close

end

No comments: