Sha256: f85dedd0c07bb4cc1ff479fddf0d43d96dd6e955ebb7c347086bf3c33794135b

Contents?: true

Size: 965 Bytes

Versions: 3

Compression:

Stored size: 965 Bytes

Contents

# coding: utf-8
#
# Class for managing cure tr (translate).
#
class CureTranslateManager
  def initialize
    @translate_from = :human_name
    @translate_to = :precure_name
    @out = $stdout
    @in = $stdin
  end

  attr_writer :out, :in

  def translate_from_to(from, to)
    @translate_from = pregex2str(from).to_sym
    @translate_to = pregex2str(to).to_sym
  end

  def str2pregex(str)
    '[:' + str + ':]'
  end

  def pregex2str(str)
    str.gsub(/\[:(.*):\]/, '\1')
  end

  def print_results
    # Create precure regular expression
    regex_tag = str2pregex(@translate_from.to_s)
    # Get patterns
    cure_pattern = Common.pregex2regex(regex_tag, true)
    # Get Key-Value
    table = Common.cure_table(@translate_from, @translate_to)
    @in.each do |line|
      updated_line = line.dup
      line.scan(/#{cure_pattern}/).each do |pat|
        updated_line.gsub!(/#{pat[0]}/, table[pat[0]])
      end
      puts updated_line
    end
    0
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cureutils-0.2.1 lib/cureutils/cure_translate_manager.rb
cureutils-0.2.0 lib/cureutils/cure_translate_manager.rb
cureutils-0.1.5 lib/cureutils/cure_translate_manager.rb