em-skkserv 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd5e8eb076bada0f59a94d5d68c879fdcca3ed36
4
+ data.tar.gz: 86b5346cf9bedc103e0e67abb6b45d116ed501eb
5
+ SHA512:
6
+ metadata.gz: e1ad61dc7f23630e577cc734b99f32aa238e0396a319643e182cfcb994e0583aa1ca7b5faee363ac4f2bf1e686f232d692413dcce562acfa52e12ed0d760fb66
7
+ data.tar.gz: f2e7c809d1ed5a9e54de62d1141d8e7a99f13138adab50d05a837b2fae2aeada5a4d618272280a160bf75e70ba6f9c6ff91643de8abac9b61059fbe62178d422
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in em-skkserv.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # EM-SKKServ
2
+
3
+ EventMachine based SKKServ.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'em-skkserv'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install em-skkserv
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'em-skkserv'
23
+
24
+ class YuiSKK < EM::SKKServ::Server
25
+ def on_request(kana)
26
+ if kana == 'ゆい'
27
+ send_data EM::SKKServ::ServerMessage.new :found, :kanji => ['唯']
28
+ else
29
+ send_data EM::SKKServ::ServerMessage.new :not_found
30
+ end
31
+ end
32
+ end
33
+
34
+ EM.run do
35
+ EM.start_server "127.0.0.1", 1178, YuiSKK
36
+ end
37
+ ```
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'em-skkserv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "em-skkserv"
8
+ spec.version = EventMachine::SKKServ::VERSION
9
+ spec.authors = ["shunirr"]
10
+ spec.email = ["m@s5r.jp"]
11
+ spec.description = %q{EventMachine based SKKServ}
12
+ spec.summary = %q{EventMachine based SKKServ}
13
+ spec.homepage = "https://github.com/shunirr/em-skkserv-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "eventmachine"
24
+ end
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $: << '../lib'
5
+
6
+ require 'em-skkserv'
7
+ require 'open-uri'
8
+
9
+ class SocialSKK < EM::SKKServ::Server
10
+ def on_request(kana)
11
+ data = open("http://www.social-ime.com/api/?string=#{URI.escape(kana)}").read
12
+ kanji = data.split "\t"
13
+ if kanji.size > 0
14
+ send_data EM::SKKServ::ServerMessage.new :found, :kanji => kanji, :encoding => 'EUC-JP'
15
+ else
16
+ send_data EM::SKKServ::ServerMessage.new :not_found
17
+ end
18
+ end
19
+ end
20
+
21
+ EM.run do
22
+ EM.start_server "127.0.0.1", 1178, SocialSKK
23
+ end
data/example/yuiskk.rb ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ $: << '../lib'
5
+
6
+ require 'em-skkserv'
7
+
8
+ class YuiSKK < EM::SKKServ::Server
9
+ def on_request(kana)
10
+ if kana == 'ゆい'
11
+ send_data EM::SKKServ::ServerMessage.new :found, :kanji => ['唯']
12
+ else
13
+ send_data EM::SKKServ::ServerMessage.new :not_found
14
+ end
15
+ end
16
+ end
17
+
18
+ EM.run do
19
+ EM.start_server "127.0.0.1", 1178, YuiSKK
20
+ end
@@ -0,0 +1,22 @@
1
+ module EventMachine
2
+ module SKKServ
3
+ class ClientMessage
4
+ COMMANDS = [
5
+ :close,
6
+ :request,
7
+ :version,
8
+ :host,
9
+ :abbrev,
10
+ ]
11
+
12
+ def self.parse(data)
13
+ data.force_encoding('EUC-JP')
14
+ command_index = data[0].to_i
15
+ end_position = data.index("\\") || data.index("\n") || data.index(" ")
16
+ kana = data[1 .. (end_position - 1)]
17
+ kana.encode!('UTF-8', 'EUC-JP')
18
+ { :command => COMMANDS[command_index], :kana => kana }
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,36 @@
1
+ module EventMachine
2
+ module SKKServ
3
+ class Server < EM::Connection
4
+ def receive_data(data)
5
+ message = ClientMessage.parse data
6
+ method = "on_#{message[:command].to_s}"
7
+ if message[:kana]
8
+ __send__ method, message[:kana]
9
+ else
10
+ __send__ method
11
+ end
12
+ close_connection_after_writing
13
+ end
14
+
15
+ def on_close
16
+ end
17
+
18
+ def on_version
19
+ send_data 'em-skkserv 0.1'
20
+ end
21
+
22
+ def on_host
23
+ send_data '0.0.0.0'
24
+ end
25
+
26
+ def on_request(kana)
27
+ send_data ServerMessage.new(:not_found).to_s
28
+ end
29
+
30
+ def on_abbrev(kana)
31
+ send_data ServerMessage.new(:not_found).to_s
32
+ end
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,29 @@
1
+ module EventMachine
2
+ module SKKServ
3
+ class ServerMessage
4
+ COMMANDS = {
5
+ :error => ?0,
6
+ :found => ?1,
7
+ :not_found => ?4,
8
+ }
9
+
10
+ def initialize(command, params = {})
11
+ @command = COMMANDS[command]
12
+ @kanji = params[:kanji]
13
+ @encoding = params[:encoding]
14
+ end
15
+
16
+ def to_s
17
+ if @kanji
18
+ kanji = @kanji
19
+ if @encoding != 'EUC-JP'
20
+ kanji.map! {|k| k.encode!('EUC-JP', @encoding) }
21
+ end
22
+ "#{@command}/#{kanji.join('/')}/\n"
23
+ else
24
+ "#{@command}\n"
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ module EventMachine
2
+ module SKKServ
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/em-skkserv.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'eventmachine'
2
+ require "em-skkserv/version"
3
+
4
+ module EventMachine
5
+ module SKKServ
6
+ autoload :Server, 'em-skkserv/server'
7
+ autoload :ServerMessage, 'em-skkserv/server_message'
8
+ autoload :ClientMessage, 'em-skkserv/client_message'
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: em-skkserv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shunirr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: eventmachine
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: EventMachine based SKKServ
56
+ email:
57
+ - m@s5r.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - em-skkserv.gemspec
68
+ - example/socialskk.rb
69
+ - example/yuiskk.rb
70
+ - lib/em-skkserv.rb
71
+ - lib/em-skkserv/client_message.rb
72
+ - lib/em-skkserv/server.rb
73
+ - lib/em-skkserv/server_message.rb
74
+ - lib/em-skkserv/version.rb
75
+ homepage: https://github.com/shunirr/em-skkserv-ruby
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.1.9
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: EventMachine based SKKServ
99
+ test_files: []