36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/IFMapper/InformWriter.rb', line 36
def new_tag(elem, str)
tag = str.dup
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('1.9.0')
utf = Iconv.new( 'iso-8859-1', 'utf-8' )
tag = utf.iconv( tag )
else
tag = tag.encode( 'utf-8', :invalid => :replace,
:undef => :replace, :replace => '' )
end
tag.gsub!(/[\s"'\/\\\-&#\,.:;!\?\n\(\)]/,'_')
tag.gsub!(/__/, '') tag.sub!(/^([\d]+)_?(.*)/, '\2\1') tag.downcase!
tag = tag[0..31]
if tag =~ @keyword
tag << '1'
end
if @tags.values.include?(tag)
idx = 2
root = tag[0..29] while @tags.values.include?(tag)
tag = "#{root}#{idx}"
idx += 1
end
end
if elem.kind_of?(String)
@tags[tag] = tag
else
@tags[elem] = tag
end
return tag
end
|