tobopomo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/exe/tobopomo ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "tobopomo"
@@ -0,0 +1,5 @@
1
+ require "json"
2
+ module Tobopomo
3
+ data_path = File.dirname(__FILE__).split("/")[0..-3].join("/") + "/data/tsi.json"
4
+ TSI = JSON.load(open(data_path))
5
+ end
@@ -0,0 +1,18 @@
1
+ module Tobopomo
2
+ LAYOUT = {
3
+ "31": "\n", "33": "!", "34": "\"", "35": "#", "36": "$",
4
+ "37": "%", "38": "&", "39": "'", "40": "(", "41": ")",
5
+ "42": "*", "43": "+", "44": "ㄝ", "45": "ㄦ", "46": "ㄡ",
6
+ "47": "ㄥ", "48": "ㄢ", "49": "ㄅ", "50": "ㄉ", "51": "ˇ",
7
+ "52": "ˋ", "53": "ㄓ", "54": "ˊ", "55": "˙", "56": "ㄚ",
8
+ "57": "ㄞ", "58": ":", "59": "ㄤ", "60": "<", "61": "=",
9
+ "62": ">", "63": "?", "64": "@", "91": "[", "92": "\\",
10
+ "93": "]", "94": "^", "95": "_", "96": "`", "97": "ㄇ",
11
+ "98": "ㄖ", "99": "ㄏ", "100": "ㄎ", "101": "ㄍ", "102": "ㄑ",
12
+ "103": "ㄕ", "104": "ㄘ", "105": "ㄛ", "106": "ㄨ", "107": "ㄜ",
13
+ "108": "ㄠ", "109": "ㄩ", "110": "ㄙ", "111": "ㄟ", "112": "ㄣ",
14
+ "113": "ㄆ", "114": "ㄐ", "115": "ㄋ", "116": "ㄔ", "117": "ㄧ",
15
+ "118": "ㄒ", "119": "ㄊ", "120": "ㄌ", "121": "ㄗ", "122": "ㄈ",
16
+ "123": "{", "124": "|", "125": "}", "126": "~" , "32": " "
17
+ }
18
+ end
@@ -0,0 +1,3 @@
1
+ module Tobopomo
2
+ VERSION = "1.0.0"
3
+ end
data/lib/tobopomo.rb ADDED
@@ -0,0 +1,57 @@
1
+ require "tobopomo/version"
2
+ require "tobopomo/data"
3
+ require "tobopomo/keymap"
4
+
5
+ module Tobopomo
6
+ def normalise(string)
7
+ string.gsub(/\s+/, "")
8
+ end
9
+ def tobopomo(input)
10
+ total = 0
11
+ input = input.chars.map{|x| Tobopomo::LAYOUT[:"#{x.ord.to_s}"]}.join("")
12
+ string = input.split(/[" "|"ˇ"|"ˋ"|"ˊ"|"˙"]/)
13
+ string = string.map.with_index{|x , index| total = total + x.length;x+input[total + index]}
14
+ return string.map{|x| normalise(x)}
15
+ end
16
+ def tokanji(input, limit=5)
17
+ if input.is_a? Array
18
+ input = input.map{|x| normalise(x)}
19
+ output = []
20
+ last = 0
21
+ input.each_with_index do | x , index|
22
+ string = input[last..index].join("")
23
+ if Tobopomo::TSI[string] && index < (input.length - 1)
24
+ next
25
+ elsif Tobopomo::TSI[string] && index == (input.length - 1)
26
+ output << Tobopomo::TSI[string][0...limit]
27
+ elsif Tobopomo::TSI[string].nil? &&index == (input.length - 1)
28
+ string = input[last...index].join("")
29
+ output << Tobopomo::TSI[string][0...limit]
30
+ output << Tobopomo::TSI[input[index]][0...limit]
31
+ else
32
+ string = input[last...index].join("")
33
+ output << Tobopomo::TSI[string][0...limit]
34
+ last = index
35
+ end
36
+ end
37
+ return output
38
+ elsif input.is_a? String
39
+ normalise(input)
40
+ return Tobopomo::TSI[input][0...limit]
41
+ end
42
+ end
43
+ end
44
+ include Tobopomo
45
+ class String
46
+ def to_bopomo
47
+ tobopomo(self)
48
+ end
49
+ def to_kanji(limit=5)
50
+ tokanji(self, limit)
51
+ end
52
+ end
53
+ class Array
54
+ def to_kanji(limit=5)
55
+ tokanji(self , limit)
56
+ end
57
+ end
data/tobopomo.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tobopomo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tobopomo"
8
+ spec.version = Tobopomo::VERSION
9
+ spec.authors = ["dylandy.chang"]
10
+ spec.email = ["dylandy.chang@gmail.com"]
11
+ spec.licenses = ["LGPL-3.0"]
12
+
13
+ spec.summary = %q{An api for convert latin alphabet straight to bopomo script and Chinese characters.}
14
+ spec.description = %q{An input method api for converting latin alphabet into human readable bopomo script and Chinese characters.}
15
+ spec.homepage = "https://github.com/dylandy/tobopomo"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.12"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tobopomo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - dylandy.chang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-19 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: An input method api for converting latin alphabet into human readable
56
+ bopomo script and Chinese characters.
57
+ email:
58
+ - dylandy.chang@gmail.com
59
+ executables:
60
+ - tobopomo
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - data/tsi.json
74
+ - exe/tobopomo
75
+ - lib/tobopomo.rb
76
+ - lib/tobopomo/data.rb
77
+ - lib/tobopomo/keymap.rb
78
+ - lib/tobopomo/version.rb
79
+ - tobopomo.gemspec
80
+ homepage: https://github.com/dylandy/tobopomo
81
+ licenses:
82
+ - LGPL-3.0
83
+ metadata:
84
+ allowed_push_host: https://rubygems.org
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.6
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: An api for convert latin alphabet straight to bopomo script and Chinese characters.
105
+ test_files: []