jkf 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jkf.rb +35 -1
- data/lib/jkf/parser/kif.rb +1 -1
- data/lib/jkf/version.rb +1 -1
- 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: ea1d397223198b08d78a958a52126942e214420a
|
4
|
+
data.tar.gz: e2381adf1ab510390fa89c4e1cc69bebdf7e2510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff617a4672e6ad4ef3653751a42089d3574f7176d39d5a6e49f5781f197531d209eb005f353ae05bfe218d909f94bf7351efdde6f035cb9c10152eaebf8b9fe8
|
7
|
+
data.tar.gz: bb6ee137c9c251f1137ddd644f9b3d5e0aa8d9d49dfbcd82bef811852d72352a2234258b085638151937f7891efeaa4ade02bdb1b5c7f2f371b44bc637edb8b6
|
data/lib/jkf.rb
CHANGED
@@ -1,7 +1,41 @@
|
|
1
|
+
require "kconv"
|
1
2
|
require "jkf/version"
|
2
3
|
require "jkf/parser"
|
3
4
|
require "jkf/converter"
|
4
5
|
|
5
6
|
module Jkf
|
6
|
-
|
7
|
+
class FileTypeError < StandardError; end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def parse_file(filename, encoding: 'Shift_JIS')
|
11
|
+
parser = case ::File.extname(filename)
|
12
|
+
when /kif/
|
13
|
+
::Jkf::Parser::Kif.new
|
14
|
+
when /ki2/
|
15
|
+
::Jkf::Parser::Ki2.new
|
16
|
+
when /csa/
|
17
|
+
::Jkf::Parser::Csa.new
|
18
|
+
when /jkf|json/
|
19
|
+
JSON
|
20
|
+
end
|
21
|
+
str = File.read(File.expand_path(filename), encoding: encoding).toutf8
|
22
|
+
parser.parse(str)
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse(str)
|
26
|
+
parsers = [::Jkf::Parser::Kif.new, ::Jkf::Parser::Ki2.new, ::Jkf::Parser::Csa.new, JSON]
|
27
|
+
|
28
|
+
result = nil
|
29
|
+
parsers.each do |parser|
|
30
|
+
begin
|
31
|
+
result = parser.parse(str)
|
32
|
+
rescue
|
33
|
+
next
|
34
|
+
end
|
35
|
+
break
|
36
|
+
end
|
37
|
+
raise FileTypeError if result.nil?
|
38
|
+
result
|
39
|
+
end
|
40
|
+
end
|
7
41
|
end
|
data/lib/jkf/parser/kif.rb
CHANGED
@@ -1506,7 +1506,7 @@ module Jkf::Parser
|
|
1506
1506
|
"切れ負け" => "TIME_UP",
|
1507
1507
|
"反則勝ち" => "ILLEGAL_ACTION", # 直前の手が反則(先頭に+か-で反則した側の情報を含める必要が有る)
|
1508
1508
|
"反則負け" => "ILLEGAL_MOVE" # ここで手番側が反則,反則の内容はコメントで表現
|
1509
|
-
}[str]
|
1509
|
+
}[str] || (raise ParseError)
|
1510
1510
|
end
|
1511
1511
|
|
1512
1512
|
def preset2str(preset)
|
data/lib/jkf/version.rb
CHANGED