Class: CureTranslateManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cureutils/cure_translate_manager.rb

Overview

Class for managing cure tr (translate).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCureTranslateManager



6
7
8
9
10
11
# File 'lib/cureutils/cure_translate_manager.rb', line 6

def initialize
  @translate_from = :human_name
  @translate_to = :precure_name
  @out = $stdout
  @in = $stdin
end

Instance Attribute Details

#in=(value) ⇒ Object (writeonly)

Sets the attribute in



13
14
15
# File 'lib/cureutils/cure_translate_manager.rb', line 13

def in=(value)
  @in = value
end

#out=(value) ⇒ Object (writeonly)

Sets the attribute out



13
14
15
# File 'lib/cureutils/cure_translate_manager.rb', line 13

def out=(value)
  @out = value
end

Instance Method Details

#pregex2str(str) ⇒ Object



24
25
26
# File 'lib/cureutils/cure_translate_manager.rb', line 24

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


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cureutils/cure_translate_manager.rb', line 28

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

#str2pregex(str) ⇒ Object



20
21
22
# File 'lib/cureutils/cure_translate_manager.rb', line 20

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

#translate_from_to(from, to) ⇒ Object



15
16
17
18
# File 'lib/cureutils/cure_translate_manager.rb', line 15

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