Module: ZhConv
- Defined in:
- lib/zhconv.rb
Defined Under Namespace
Classes: Converter
Constant Summary collapse
- VARIANTS =
["zh-hans", "zh-hant", "zh-cn", "zh-sg", "zh-tw", "zh-hk"]
Class Method Summary collapse
- .convert(variant, message, use_web = true) ⇒ Object
- .converter_url(variant, web_converter = false) ⇒ Object
- .local_converter(variant) ⇒ Object
- .web_converter(variant) ⇒ Object
Class Method Details
.convert(variant, message, use_web = true) ⇒ Object
32 33 34 35 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 |
# File 'lib/zhconv.rb', line 32 def self.convert(variant, , use_web=true) if use_web case variant when "zh-cn", "zh-sg" converter = web_converter(variant) = converter.convert() when "zh-tw", "zh-hk" converter = web_converter(variant) = converter.convert() end end case variant when "zh-cn", "zh-sg" converter = local_converter(variant) = converter.convert() when "zh-tw", "zh-hk" converter = local_converter(variant) = converter.convert() end if use_web case variant when "zh-hans", "zh-cn", "zh-sg" converter = web_converter("zh-hans") = converter.convert() when "zh-hant", "zh-tw", "zh-hk" converter = web_converter("zh-hant") = converter.convert() end end case variant when "zh-hans", "zh-cn", "zh-sg" converter = local_converter("zh-hans") = converter.convert() when "zh-hant", "zh-tw", "zh-hk" converter = local_converter("zh-hant") = converter.convert() end end |
.converter_url(variant, web_converter = false) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/zhconv.rb', line 88 def self.converter_url(variant, web_converter=false) if web_converter "http://zh.wikipedia.org/w/index.php?title=MediaWiki:Conversiontable/#{variant}&action=raw&templates=expand" else File.(File.dirname(__FILE__)) + "/../data/#{variant}.txt" end end |
.local_converter(variant) ⇒ Object
76 77 78 79 80 |
# File 'lib/zhconv.rb', line 76 def self.local_converter(variant) raise "variant #{variant} not supported" unless VARIANTS.index(variant) url = converter_url(variant, false) @converters[url] ||= Converter.new(url) end |
.web_converter(variant) ⇒ Object
82 83 84 85 86 |
# File 'lib/zhconv.rb', line 82 def self.web_converter(variant) raise "variant #{variant} not supported" unless VARIANTS.index(variant) url = converter_url(variant, true) @converters[url] ||= Converter.new(url) end |