Class: CBin::Trans::Helper
- Inherits:
-
Object
- Object
- CBin::Trans::Helper
- Defined in:
- lib/cocoapods-lhj-bin/helpers/trans_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #down_load_yaml ⇒ Object
- #load_trans_map ⇒ Object
- #trans_zh_cn_str(input) ⇒ Object
- #trans_zh_hk_str(input) ⇒ Object
- #yaml_file ⇒ Object
Class Method Details
permalink .instance ⇒ Object
[View source]
6 7 8 |
# File 'lib/cocoapods-lhj-bin/helpers/trans_helper.rb', line 6 def self.instance @instance ||= new end |
Instance Method Details
permalink #down_load_yaml ⇒ Object
[View source]
21 22 23 24 25 26 27 28 |
# File 'lib/cocoapods-lhj-bin/helpers/trans_helper.rb', line 21 def down_load_yaml require 'open-uri' URI.open('http://aomi-ios-repo.oss-cn-shenzhen.aliyuncs.com/zh2hant.yml') do |i| File.open(yaml_file, 'w+') do |f| f.write(i.read) end end end |
permalink #load_trans_map ⇒ Object
[View source]
14 15 16 17 18 19 |
# File 'lib/cocoapods-lhj-bin/helpers/trans_helper.rb', line 14 def load_trans_map require 'yaml' down_load_yaml unless File.exist?(yaml_file) contents = YAML.safe_load(File.open(yaml_file)) contents.to_hash end |
permalink #trans_zh_cn_str(input) ⇒ Object
[View source]
30 31 32 33 34 35 36 37 |
# File 'lib/cocoapods-lhj-bin/helpers/trans_helper.rb', line 30 def trans_zh_cn_str(input) @trans_map_invert ||= load_trans_map.invert out = [] input.each_char do |c| out << (@trans_map_invert[c] || c) end out.join('') end |
permalink #trans_zh_hk_str(input) ⇒ Object
[View source]
39 40 41 42 43 44 45 46 |
# File 'lib/cocoapods-lhj-bin/helpers/trans_helper.rb', line 39 def trans_zh_hk_str(input) @trans_map ||= load_trans_map out = [] input.each_char do |c| out << (@trans_map[c] || c) end out.join('') end |
permalink #yaml_file ⇒ Object
[View source]
10 11 12 |
# File 'lib/cocoapods-lhj-bin/helpers/trans_helper.rb', line 10 def yaml_file File.join(Pod::Config.instance.home_dir, 'zh2hant.yml') end |