Class: ZhConv::Converter
- Inherits:
-
Object
- Object
- ZhConv::Converter
- Defined in:
- lib/zhconv.rb
Instance Method Summary collapse
- #convert(input) ⇒ Object
-
#initialize(url) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(url) ⇒ Converter
Returns a new instance of Converter.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/zhconv.rb', line 12 def initialize(url) @mapping = {} table = open(url).read table.lines do |line| matches = line.match(/^[\*\"]([^\"=]+)\"?\s*=>\s*\"?([^\s\/\"]+)\s?.*\"?[;,]$/) if matches @mapping[matches[1].strip] = matches[2].strip end end #puts "create converter for (#{url}), words: #{@mapping.size}" end |
Instance Method Details
#convert(input) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/zhconv.rb', line 24 def convert(input) @mapping.each_key do |key| input.gsub!(key, @mapping[key]) end input end |