ctc 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/ctc.gemspec ADDED
@@ -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 'ctc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ctc"
8
+ spec.version = Ctc::VERSION
9
+ spec.authors = ["Hao Liu"]
10
+ spec.email = ["leomayleomay@gmail.com"]
11
+ spec.description = %q{China Telegraph Code (CTC)}
12
+ spec.summary = %q{China Telegraph Code (CTC)}
13
+ spec.homepage = ""
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 "rspec"
24
+ end
@@ -0,0 +1,16 @@
1
+ class Ctc2Kanji
2
+ def self.find(kanji)
3
+ mappings.fetch(kanji) do
4
+ raise Ctc::CtcNotFoundError.new("China Telelgraph Code (CTC) not found.")
5
+ end
6
+ end
7
+
8
+ private
9
+ def self.mappings
10
+ return @mappings if @mappings
11
+
12
+ yaml_file = File.expand_path("../../config/ctc_2_kanji.yml", File.dirname(__FILE__))
13
+ @mappings = YAML.load_file(yaml_file)
14
+ @mappings
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class Kanji2Ctc
2
+ def self.find(kanji)
3
+ mappings.fetch(kanji) do
4
+ raise Ctc::KanjiNotFoundError.new("Kanji not found.")
5
+ end
6
+ end
7
+
8
+ private
9
+ def self.mappings
10
+ return @mappings if @mappings
11
+
12
+ yaml_file = File.expand_path("../../config/kanji_2_ctc.yml", File.dirname(__FILE__))
13
+ @mappings = YAML.load_file(yaml_file)
14
+ @mappings
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Ctc
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ctc.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "ctc/version"
2
+ require "ctc/kanji_2_ctc"
3
+ require "ctc/ctc_2_kanji"
4
+
5
+ module Ctc
6
+ class KanjiNotFoundError < StandardError; end
7
+ class CtcNotFoundError < StandardError; end
8
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ctc2Kanji do
4
+ it "raises error for nil input" do
5
+ expect {Ctc2Kanji.find(nil)}.to raise_error(Ctc::CtcNotFoundError)
6
+ end
7
+
8
+ it "raises error for empty input" do
9
+ expect {Ctc2Kanji.find("")}.to raise_error(Ctc::CtcNotFoundError)
10
+ end
11
+
12
+ it "raises error for invalid input" do
13
+ expect {Ctc2Kanji.find(1)}.to raise_error(Ctc::CtcNotFoundError)
14
+ end
15
+
16
+ it "returns ctc for valid input" do
17
+ Ctc2Kanji.find("0491").should == "刘"
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Kanji2Ctc do
4
+ it "raises error for nil input" do
5
+ expect {Kanji2Ctc.find(nil)}.to raise_error(Ctc::KanjiNotFoundError)
6
+ end
7
+
8
+ it "raises error for empty input" do
9
+ expect {Kanji2Ctc.find("")}.to raise_error(Ctc::KanjiNotFoundError)
10
+ end
11
+
12
+ it "raises error for invalid input" do
13
+ expect {Kanji2Ctc.find(1)}.to raise_error(Ctc::KanjiNotFoundError)
14
+ end
15
+
16
+ it "returns ctc for valid input" do
17
+ Kanji2Ctc.find("刘").should == "0491"
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+
5
+ require 'ctc'
6
+
7
+ RSpec.configure do |config|
8
+ # Use color in STDOUT
9
+ config.color_enabled = true
10
+
11
+ # Use color not only in STDOUT but also in pagers and files
12
+ config.tty = true
13
+
14
+ # Use the specified formatter
15
+ config.formatter = :documentation # :progress, :html
16
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ctc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hao Liu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-20 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: rspec
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: China Telegraph Code (CTC)
56
+ email:
57
+ - leomayleomay@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rvmrc
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - config/ctc_2_kanji.yml
69
+ - config/kanji_2_ctc.yml
70
+ - ctc.gemspec
71
+ - lib/ctc.rb
72
+ - lib/ctc/ctc_2_kanji.rb
73
+ - lib/ctc/kanji_2_ctc.rb
74
+ - lib/ctc/version.rb
75
+ - spec/ctc_2_kanji_spec.rb
76
+ - spec/kanji_2_ctc_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: ''
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.2.2
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: China Telegraph Code (CTC)
102
+ test_files:
103
+ - spec/ctc_2_kanji_spec.rb
104
+ - spec/kanji_2_ctc_spec.rb
105
+ - spec/spec_helper.rb