ropencc 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ropencc.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ ropencc
2
+ =======
3
+ ropencc is a project for conversion between Traditional and Simplified Chinese, wrapper in ruby.
4
+ Open Chinese Convert(OpenCC)「開放中文轉換」,是一個致力於中文簡繁轉換的項目,提供高質量詞庫和函數庫(libopencc)。<a href='http://code.google.com/p/opencc/'>更多介紹</a>。
5
+
6
+ Install
7
+ -------
8
+ 先安装 libopencc
9
+
10
+ Ubuntu
11
+ 如果你正在使用Ubuntu 10.10 (Maverick) 以上的版本,opencc已經被加入到了官方源中,使用
12
+ sudo apt-get install opencc
13
+ 如果你更願意體驗最新的版本,請使用ppa:
14
+ sudo add-apt-repository ppa:byvoid-kcp/ppa
15
+ sudo apt-get update
16
+ sudo apt-get install opencc
17
+
18
+
19
+ Mac OS X
20
+ 使用 brew 安装
21
+ brew install opencc
22
+
23
+ 更多安装 libopencc 介绍请查看: <http://code.google.com/p/opencc/wiki/Install>
24
+
25
+ Usage
26
+ -----
27
+ 简转繁
28
+ Ropencc.conv('simp_to_trad',text)
29
+ 繁转简
30
+ Ropencc.conv('trad_to_simp',text)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Ropencc
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ropencc.rb ADDED
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'ffi'
3
+ require "ropencc/version"
4
+
5
+ module Ropencc
6
+ module LibOpenCC
7
+ extend FFI::Library
8
+ ffi_lib 'opencc'
9
+ attach_function :opencc_open, [:string], :pointer
10
+ attach_function :opencc_close, [:pointer], :int
11
+ attach_function :opencc_convert_utf8, [:pointer, :string, :int], :pointer
12
+ attach_function :opencc_convert, [:pointer, :string, :int], :int
13
+ attach_function :opencc_perror, [:string], :void
14
+ attach_function :opencc_dict_load, [:pointer, :string, :int], :int
15
+ end
16
+ module LibC
17
+ extend FFI::Library
18
+ ffi_lib FFI::Library::LIBC
19
+ attach_function :free, [:pointer], :void
20
+ end # module LibC
21
+
22
+ DICTS = {
23
+ :simp_to_trad => ['simp_to_trad_characters.ocd','simp_to_trad_phrases.ocd','simp_to_trad_variant.ocd'],
24
+ :trad_to_simp => ['trad_to_simp_characters.ocd','trad_to_simp_phrases.ocd','trad_to_simp_variant.ocd']
25
+ }
26
+
27
+ class << self
28
+ def conv(dicttype, str)
29
+ od = LibOpenCC.opencc_open nil
30
+ DICTS[dicttype.to_sym].each { |dict| LibOpenCC.opencc_dict_load(od, dict, 1) }
31
+ ptr = LibOpenCC.opencc_convert_utf8(od, str, str.bytesize)
32
+ out_str = ptr.read_string
33
+ LibC.free ptr
34
+ LibOpenCC.opencc_close od
35
+ out_str
36
+ end
37
+ end
38
+ end
data/ropencc.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ropencc/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Psi"]
6
+ gem.email = ["psi.xie@gmail.com"]
7
+ gem.description = %q{ a project for conversion between Traditional and Simplified Chinese, wrapper in ruby. }
8
+ gem.summary = %q{ a project for conversion between Traditional and Simplified Chinese. }
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "ropencc"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Ropencc::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ropencc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Psi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-27 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! ' a project for conversion between Traditional and Simplified Chinese,
15
+ wrapper in ruby. '
16
+ email:
17
+ - psi.xie@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - lib/ropencc.rb
27
+ - lib/ropencc/version.rb
28
+ - ropencc.gemspec
29
+ homepage: ''
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.10
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: a project for conversion between Traditional and Simplified Chinese.
53
+ test_files: []