Class: GoogleImeSkk
Defined Under Namespace
Modules: CLI
Constant Summary collapse
- VERSION_STRING =
"GoogleImeSKK0.1 "
Constants inherited from SocialSKK
SocialSKK::BUFSIZE, SocialSKK::CLIENT_END, SocialSKK::CLIENT_HOST, SocialSKK::CLIENT_REQUEST, SocialSKK::CLIENT_VERSION, SocialSKK::SERVER_ERROR, SocialSKK::SERVER_FOUND, SocialSKK::SERVER_NOT_FOUND, SocialSKK::TIMEOUT
Instance Method Summary collapse
Methods inherited from SocialSKK
Constructor Details
This class inherits a constructor from SocialSKK
Instance Method Details
#encode_to_eucjp(text) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/google-ime-skk.rb', line 18 def encode_to_eucjp(text) if String.new.respond_to?(:encode) text.encode('euc-jp', 'utf-8', {:invaild => true, :replace => '?'}) else require 'kconv' Kconv.toeuc(text) end end |
#encode_to_utf8(text) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/google-ime-skk.rb', line 9 def encode_to_utf8(text) if String.new.respond_to?(:encode) text.encode('utf-8', 'euc-jp') else require 'kconv' Kconv.toutf8(text) end end |
#social_ime_search(text) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/google-ime-skk.rb', line 27 def (text) text = encode_to_utf8(text) text = text.sub(/[a-z]?$/) { |m| ',' + m } uri = URI.parse 'http://www.google.com/transliterate' http = Net::HTTP.new(uri.host, uri.port) http = Net::HTTP.new(uri.host, uri.port, @proxy.host, @proxy.port) if @proxy begin http.read_timeout = 1 http.open_timeout = 1 http.start do |h| res = h.get("/transliterate?langpair=ja-Hira%7Cja&text=" + URI.escape(text)) obj = JSON.parse(res.body.to_s) encode_to_eucjp(obj[0][1].join('/')) end rescue => e warn e return nil end end |