Class: TranslateLogic
Overview
Class for managing cure tr (translate).
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from BaseLogic
#source_err, #source_input, #source_output
Constructor Details
9
10
11
12
13
|
# File 'lib/cureutils/logic/translate_logic.rb', line 9
def initialize
super
@translate_from = :human_name
@translate_to = :precure_name
end
|
Instance Attribute Details
#in=(value) ⇒ Object
15
16
17
|
# File 'lib/cureutils/logic/translate_logic.rb', line 15
def in=(value)
@in = value
end
|
Instance Method Details
#pregex2str(str) ⇒ Object
26
27
28
|
# File 'lib/cureutils/logic/translate_logic.rb', line 26
def pregex2str(str)
str.gsub(/\[:(.*):\]/, '\1')
end
|
#print_results ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cureutils/logic/translate_logic.rb', line 30
def print_results
regex_tag = str2pregex(@translate_from.to_s)
cure_pattern = Common.pregex2regex(regex_tag, true)
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
@out.puts updated_line
end
0
end
|
#str2pregex(str) ⇒ Object
22
23
24
|
# File 'lib/cureutils/logic/translate_logic.rb', line 22
def str2pregex(str)
'[:' + str + ':]'
end
|
#translate_from_to(from, to) ⇒ Object
17
18
19
20
|
# File 'lib/cureutils/logic/translate_logic.rb', line 17
def translate_from_to(from, to)
@translate_from = pregex2str(from).to_sym
@translate_to = pregex2str(to).to_sym
end
|