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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 62e414ef9443049f0ab631af44d70072f7c7e55e
4
- data.tar.gz: 2ead76a04ded9f63ed4b0ddf13dfa107d65f2072
3
+ metadata.gz: ea1d397223198b08d78a958a52126942e214420a
4
+ data.tar.gz: e2381adf1ab510390fa89c4e1cc69bebdf7e2510
5
5
  SHA512:
6
- metadata.gz: 2c5e351ed8a6479d9e2b620cba5cdf96da8f82adf818c1243c6a7150cc5178dad6853e108ed97379f351215e758a159f8f860e15b134df80d74494f700177367
7
- data.tar.gz: 98ce473672fd1a672b7a1fc35f627508920632ddf7d706f398e8a4f7a03123b731c1e0baf2c6d6fe2f36408ae9b75a30d56d3ed64a4fceb5faa12474101e7832
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
- # Your code goes here...
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Jkf
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jkf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iyuuya