Sha256: a5cee2270a0f68ee82546218b9634e5f885ebad13e3c94a0c093bc18096dc2ea

Contents?: true

Size: 986 Bytes

Versions: 2

Compression:

Stored size: 986 Bytes

Contents

require 'rubygems'
require 'socialskk'
require 'cgi'
require 'json'

class GoogleImeSkk < SocialSKK
  VERSION_STRING   = "GoogleImeSKK0.1 "

  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

  def encode_to_eucjp(text)
    if String.new.respond_to?(:encode)
      text.encode('euc-jp', 'utf-8')
    else
      require 'kconv'
      Kconv.toeuc(text)
    end
  end

  def social_ime_search(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
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
google-ime-skk-1.1.0 lib/google-ime-skk.rb
google-ime-skk-1.0.0 lib/google-ime-skk.rb