glitch-ime 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.5.2)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.8.7)
11
+ rcov (0.9.9)
12
+ rspec (2.3.0)
13
+ rspec-core (~> 2.3.0)
14
+ rspec-expectations (~> 2.3.0)
15
+ rspec-mocks (~> 2.3.0)
16
+ rspec-core (2.3.1)
17
+ rspec-expectations (2.3.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.3.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.5.2)
27
+ rcov
28
+ rspec (~> 2.3.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 hitode909
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ = glitch-ime
2
+
3
+ Glitch IME using Google CGI API for Japanese Input.
4
+
5
+ == Example
6
+ require 'glitch-ime'
7
+
8
+ ime = GlitchIME.new('にわにはにわにわわにがいます')
9
+
10
+ 10.times {
11
+ puts img.generate
12
+ }
13
+
14
+
15
+ This script will puts below.
16
+
17
+ ニワニハニワ二輪わにがイマス
18
+ ニワニハニワ二話ワニが鋳ます
19
+ ニワニハニワニワ王仁が射ます
20
+ 庭には二羽ニワ王仁が射ます
21
+ にわにはにわ丹羽waniが射ます
22
+ ニワニハニワ庭わにがイマス
23
+ 庭には二羽庭王仁がイマス
24
+ ニワニハニワ丹羽王仁が鋳ます
25
+ ニワニハニワニワわにがイマス
26
+ 庭には二羽ニワわにが射ます
27
+
28
+
29
+ == Copyright
30
+
31
+ Copyright (c) 2011 hitode909. See LICENSE.txt for
32
+ further details.
33
+
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "glitch-ime"
16
+ gem.homepage = "http://github.com/hitode909/glitch-ime"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Glitch IME}
19
+ gem.description = %Q{Glitch IME using Google CGI API for Japanese Input}
20
+ gem.email = "hitode909@gmail.com"
21
+ gem.authors = ["hitode909"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
36
+ spec.pattern = 'spec/**/*_spec.rb'
37
+ spec.rcov = true
38
+ end
39
+
40
+ task :default => :spec
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "glitch-ime #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{glitch-ime}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["hitode909"]
12
+ s.date = %q{2011-02-20}
13
+ s.description = %q{Glitch IME using Google CGI API for Japanese Input}
14
+ s.email = %q{hitode909@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "glitch-ime.gemspec",
29
+ "lib/glitch-ime.rb",
30
+ "spec/glitch-ime_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/hitode909/glitch-ime}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.5.2}
37
+ s.summary = %q{Glitch IME}
38
+ s.test_files = [
39
+ "spec/glitch-ime_spec.rb",
40
+ "spec/spec_helper.rb"
41
+ ]
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ end
63
+ end
64
+
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'cgi'
4
+ require 'open-uri'
5
+
6
+ class GlitchIME
7
+ def initialize(text)
8
+ @text = text
9
+ end
10
+
11
+ def generate
12
+ result = ''
13
+ patterns.each{|pair|
14
+ key, values = *pair
15
+ result += choice(values)
16
+ }
17
+ result
18
+ end
19
+
20
+ private
21
+ def patterns
22
+ @json ||= begin
23
+ url = "http://www.google.com/transliterate?langpair=ja-Hira%7Cja&text=" + CGI.escape(@text)
24
+ src = open(url).read.gsub(/\n/, '').gsub(/,\]/, ']')
25
+ JSON.parse(src)
26
+ end
27
+ end
28
+
29
+ def choice(array)
30
+ if array.respond_to? :choice
31
+ array.choice
32
+ elsif array.respond_to? :sample
33
+ array.sample
34
+ else
35
+ array[(rand * array.length).to_i ]
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+
4
+ describe "Glitchime" do
5
+ it "can create instance" do
6
+ lambda{ GlitchIME.new }.should raise_error(ArgumentError)
7
+ GlitchIME.new('こんにちは').should be_kind_of GlitchIME
8
+ end
9
+
10
+ it "can glitch text" do
11
+ source = 'あけましておめでとうございます,きゅうねんちゅうはおせわになりました,ことしはよろしくおねがいいたします'
12
+ ime = GlitchIME.new(source)
13
+ ime.generate.should be_kind_of String
14
+ ime.generate.should_not equal source
15
+ end
16
+
17
+ it "can generate many text" do
18
+ source = 'あけましておめでとうございます,きゅうねんちゅうはおせわになりました,ことしはよろしくおねがいいたします'
19
+ ime = GlitchIME.new(source)
20
+ (1..10).map{ ime.generate }.uniq.should have_at_least(2).items
21
+ end
22
+
23
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'glitch-ime'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glitch-ime
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - hitode909
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-02-20 00:00:00.000000000 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ requirement: &2156624560 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 2.3.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: *2156624560
26
+ - !ruby/object:Gem::Dependency
27
+ name: bundler
28
+ requirement: &2156623380 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2156623380
37
+ - !ruby/object:Gem::Dependency
38
+ name: jeweler
39
+ requirement: &2156622160 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 1.5.2
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2156622160
48
+ - !ruby/object:Gem::Dependency
49
+ name: rcov
50
+ requirement: &2156620940 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2156620940
59
+ description: Glitch IME using Google CGI API for Japanese Input
60
+ email: hitode909@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.txt
65
+ - README.rdoc
66
+ files:
67
+ - .document
68
+ - .rspec
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.txt
72
+ - README.rdoc
73
+ - Rakefile
74
+ - VERSION
75
+ - glitch-ime.gemspec
76
+ - lib/glitch-ime.rb
77
+ - spec/glitch-ime_spec.rb
78
+ - spec/spec_helper.rb
79
+ has_rdoc: true
80
+ homepage: http://github.com/hitode909/glitch-ime
81
+ licenses:
82
+ - MIT
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ segments:
94
+ - 0
95
+ hash: 3795874382490862443
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.5.2
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Glitch IME
108
+ test_files:
109
+ - spec/glitch-ime_spec.rb
110
+ - spec/spec_helper.rb