Class: Zh
- Inherits:
-
Object
- Object
- Zh
- Defined in:
- lib/zh.rb,
lib/zh/version.rb
Constant Summary collapse
- LOCALE =
[:cn, :sg, :tw, :hk]
- VERSION =
"0.0.1"
Class Method Summary collapse
Class Method Details
.converter(method, message) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/zh.rb', line 21 def converter(method, ) if method == :tw || method == :hk localize_json = file_parser(method) localize_json.each_key { |k| .gsub!(k, localize_json[k]) } traditionalize_json = file_parser("hant") traditionalize_json.each_key { |k| .gsub!(k, traditionalize_json[k]) } elsif method == :cn || method == :sg localize_json = file_parser(method) localize_json.each_key { |k| .gsub!(k, localize_json[k]) } simplify_json = file_parser("hans") simplify_json.each_key { |k| .gsub!(k, simplify_json[k]) } end end |
.update_data ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/zh.rb', line 36 def update_data variants = [:cn, :sg, :tw, :hk, :hans, :hant] variants.each do |l| json = file_parser(l) url = "http://zh.wikipedia.org/w/index.php?title=MediaWiki:Conversiontable/zh-#{l}&action=raw&templates=expand" table = open(url).read table.lines do |line| matches = line.match(/^[\*\"]([^\"=]+)\"?\s*=>\s*\"?([^\s\/\"]+)\s?.*\"?[;,]$/) if matches json[matches[1].strip] = matches[2].strip end end write_to_json(l, json) end true end |