ctc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ctc/ctc_2_kanji.rb +13 -11
- data/lib/ctc/kanji_2_ctc.rb +13 -11
- data/lib/ctc/version.rb +1 -1
- data/spec/ctc_2_kanji_spec.rb +5 -5
- data/spec/kanji_2_ctc_spec.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 250d5bfb4d0d093804c0e1acbc327325d4d9b99f
|
4
|
+
data.tar.gz: 86e395d270bfbb295f145f545da593b5e8d268f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69e0cb27b8567c4a4d9420d4730544daf51e700a9d561d34dc2adffef2988592f2f04448922318918894f2d848744628aa8eb6a7825faf2f5a527fc6c76b7f81
|
7
|
+
data.tar.gz: b9f9ea90ea15d36e1ff03ba934c0cc28f76e553d4e570436f503ba3adc9223e60bf5a9a5a92047a798def03b44f254ba2c82dbcfbd5929658d19e15bbf814c0f
|
data/lib/ctc/ctc_2_kanji.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Ctc
|
2
|
+
class Ctc2Kanji
|
3
|
+
def self.find(kanji)
|
4
|
+
mappings.fetch(kanji) do
|
5
|
+
raise Ctc::CtcNotFoundError.new("China Telelgraph Code (CTC) not found.")
|
6
|
+
end
|
5
7
|
end
|
6
|
-
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
private
|
10
|
+
def self.mappings
|
11
|
+
return @mappings if @mappings
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
yaml_file = File.expand_path("../../config/ctc_2_kanji.yml", File.dirname(__FILE__))
|
14
|
+
@mappings = YAML.load_file(yaml_file)
|
15
|
+
@mappings
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/ctc/kanji_2_ctc.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Ctc
|
2
|
+
class Kanji2Ctc
|
3
|
+
def self.find(kanji)
|
4
|
+
mappings.fetch(kanji) do
|
5
|
+
raise Ctc::KanjiNotFoundError.new("Kanji not found.")
|
6
|
+
end
|
5
7
|
end
|
6
|
-
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
private
|
10
|
+
def self.mappings
|
11
|
+
return @mappings if @mappings
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
yaml_file = File.expand_path("../../config/kanji_2_ctc.yml", File.dirname(__FILE__))
|
14
|
+
@mappings = YAML.load_file(yaml_file)
|
15
|
+
@mappings
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/ctc/version.rb
CHANGED
data/spec/ctc_2_kanji_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Ctc2Kanji do
|
3
|
+
describe Ctc::Ctc2Kanji do
|
4
4
|
it "raises error for nil input" do
|
5
|
-
expect {Ctc2Kanji.find(nil)}.to raise_error(Ctc::CtcNotFoundError)
|
5
|
+
expect {Ctc::Ctc2Kanji.find(nil)}.to raise_error(Ctc::CtcNotFoundError)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "raises error for empty input" do
|
9
|
-
expect {Ctc2Kanji.find("")}.to raise_error(Ctc::CtcNotFoundError)
|
9
|
+
expect {Ctc::Ctc2Kanji.find("")}.to raise_error(Ctc::CtcNotFoundError)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "raises error for invalid input" do
|
13
|
-
expect {Ctc2Kanji.find(1)}.to raise_error(Ctc::CtcNotFoundError)
|
13
|
+
expect {Ctc::Ctc2Kanji.find(1)}.to raise_error(Ctc::CtcNotFoundError)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns ctc for valid input" do
|
17
|
-
Ctc2Kanji.find("0491").should == "刘"
|
17
|
+
Ctc::Ctc2Kanji.find("0491").should == "刘"
|
18
18
|
end
|
19
19
|
end
|
data/spec/kanji_2_ctc_spec.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Kanji2Ctc do
|
3
|
+
describe Ctc::Kanji2Ctc do
|
4
4
|
it "raises error for nil input" do
|
5
|
-
expect {Kanji2Ctc.find(nil)}.to raise_error(Ctc::KanjiNotFoundError)
|
5
|
+
expect {Ctc::Kanji2Ctc.find(nil)}.to raise_error(Ctc::KanjiNotFoundError)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "raises error for empty input" do
|
9
|
-
expect {Kanji2Ctc.find("")}.to raise_error(Ctc::KanjiNotFoundError)
|
9
|
+
expect {Ctc::Kanji2Ctc.find("")}.to raise_error(Ctc::KanjiNotFoundError)
|
10
10
|
end
|
11
11
|
|
12
12
|
it "raises error for invalid input" do
|
13
|
-
expect {Kanji2Ctc.find(1)}.to raise_error(Ctc::KanjiNotFoundError)
|
13
|
+
expect {Ctc::Kanji2Ctc.find(1)}.to raise_error(Ctc::KanjiNotFoundError)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns ctc for valid input" do
|
17
|
-
Kanji2Ctc.find("刘").should == "0491"
|
17
|
+
Ctc::Kanji2Ctc.find("刘").should == "0491"
|
18
18
|
end
|
19
19
|
end
|