From 810ac42879ec4d8ab76ae85abaa878aebaea83d8 Mon Sep 17 00:00:00 2001 From: Shimpei Otsubo Date: Fri, 16 Aug 2024 18:52:44 +0900 Subject: [PATCH 1/4] Allow multiple target --- .gitignore | 1 + Rakefile | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 09715c5..f90ab01 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ /dist/ /pkg/ /*.txt +/*.nrset .bundle vendor diff --git a/Rakefile b/Rakefile index cf74feb..6c44fc7 100644 --- a/Rakefile +++ b/Rakefile @@ -8,12 +8,17 @@ RSpec::Core::RakeTask.new(:spec) task default: :package CONFS = { - 'anpan.txt': 'anpan.yaml', - 'google_japanese_input.txt': 'google_japanese_input.yaml', - 'dvorakjp_prime.txt': 'dvorakjp.yaml', + anpan: 'anpan.yaml', + google_japanese_input: 'google_japanese_input.yaml', + dvorakjp_prime: 'dvorakjp.yaml', } -TABLE_PATHS = CONFS.keys.map(&:to_s) +TARGETS = { + google_japanese_input: ".txt", kawasemi: ".nrset" +} + +TABLE_PATHS = CONFS.keys.map {|k| TARGETS.map {|t, ext| "#{k}#{ext}" } }.flatten + package_task = Rake::PackageTask.new("tables", Anpan::VERSION) do |p| p.need_zip = true p.package_files.include TABLE_PATHS @@ -28,9 +33,13 @@ def output_to_file(filename, conf) end end -CONFS.each do |filename, conf| - file filename do - output_to_file filename, conf +CONFS.each do |key, conf| + TARGETS.each do |k, ext| + filename = "#{key}#{ext}" + + file filename do + output_to_file filename, conf + end end end From e6cef70eaf564276e31749df3c1bb3041eab1cd6 Mon Sep 17 00:00:00 2001 From: Shimpei Otsubo Date: Fri, 16 Aug 2024 18:54:47 +0900 Subject: [PATCH 2/4] Pass target --- Rakefile | 8 ++++---- lib/anpan.rb | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Rakefile b/Rakefile index 6c44fc7..52985ab 100644 --- a/Rakefile +++ b/Rakefile @@ -26,19 +26,19 @@ end file package_task.package_dir_path => TABLE_PATHS -def output_to_file(filename, conf) +def output_to_file(filename, conf, target) puts filename File.open(filename.to_s, 'w') do |file| - file.write Anpan.new(conf).render + file.write Anpan.new(conf).render(target) end end CONFS.each do |key, conf| - TARGETS.each do |k, ext| + TARGETS.each do |target, ext| filename = "#{key}#{ext}" file filename do - output_to_file filename, conf + output_to_file filename, conf, target end end end diff --git a/lib/anpan.rb b/lib/anpan.rb index e83a7d2..5353c55 100644 --- a/lib/anpan.rb +++ b/lib/anpan.rb @@ -18,7 +18,12 @@ def table(args = {}) @an.table(args) end - def render - @an.patterns.map(&:render).join("\n") + def render(target) + case target + when :google_japanese_input + @an.patterns.map(&:render).join("\n") + when :kawasemi + "" # TODO: implement + end end end From 9a372c2483e894480f7dd414cb844d4d0c1756ad Mon Sep 17 00:00:00 2001 From: Shimpei Otsubo Date: Fri, 16 Aug 2024 20:07:57 +0900 Subject: [PATCH 3/4] Add kasawemi support --- Gemfile | 1 + Gemfile.lock | 4 ++++ lib/anpan.rb | 19 +++++++++++++++++-- lib/anpan/pattern.rb | 18 ++++++++++++++++-- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index a9d692c..291fc37 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,4 @@ source 'https://rubygems.org' gemspec gem 'rspec' gem 'rake' +gem 'rexml' diff --git a/Gemfile.lock b/Gemfile.lock index 76034f5..9f4cfd8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -19,6 +19,8 @@ GEM concurrent-ruby (~> 1.0) minitest (5.14.3) rake (13.2.1) + rexml (3.3.5) + strscan rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -32,6 +34,7 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.0) + strscan (3.1.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0) zeitwerk (2.4.2) @@ -42,6 +45,7 @@ PLATFORMS DEPENDENCIES anpan! rake + rexml rspec BUNDLED WITH diff --git a/lib/anpan.rb b/lib/anpan.rb index 5353c55..d8ae18a 100644 --- a/lib/anpan.rb +++ b/lib/anpan.rb @@ -1,4 +1,5 @@ require 'yaml' +require 'rexml/document' require 'anpan/vowel' require 'anpan/consonant' require 'anpan/an' @@ -21,9 +22,23 @@ def table(args = {}) def render(target) case target when :google_japanese_input - @an.patterns.map(&:render).join("\n") + @an.patterns.map { |p| p.render(target) }.join("\n") when :kawasemi - "" # TODO: implement + doc = REXML::Document.new + doc << REXML::XMLDecl.new('1.0', 'UTF-8') + plist = REXML::Element.new('plist') + plist.add_attribute('version', '1.0') + dict = REXML::Element.new('dict') + + @an.patterns.each do |p| + p.render(target).each do |e| + dict << e + end + end + plist << dict + doc << plist + + doc.to_s end end end diff --git a/lib/anpan/pattern.rb b/lib/anpan/pattern.rb index c4c8501..b73339b 100644 --- a/lib/anpan/pattern.rb +++ b/lib/anpan/pattern.rb @@ -1,4 +1,5 @@ require 'anpan/pattern/table' +require 'rexml/document' class Anpan class Pattern @@ -10,9 +11,22 @@ def initialize(input, output = input, addition = nil, as_is = false) @as_is = as_is end - def render + def render(target = :google_japanese_input) output = @as_is ? @output : output_jp - [@input, output, @addition].join("\t").gsub(/\t+$/, '') + + case target + when :google_japanese_input + [@input, output, @addition].join("\t").gsub(/\t+$/, '') + when :kawasemi + # かわせみは自動で tt -> っt に変換してくれるのでそれを阻害しないようにする + return [] unless @addition.empty? + + key = REXML::Element.new('key') + key.text = @input + value = REXML::Element.new('string') + value.text = output + [key, value] + end end def to_h From 8952e1fa0ba94847daf8c8d5d3efba20b154ddc1 Mon Sep 17 00:00:00 2001 From: Shimpei Otsubo Date: Fri, 16 Aug 2024 20:10:04 +0900 Subject: [PATCH 4/4] Update rspec --- Gemfile.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9f4cfd8..de2e2f7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,26 +14,26 @@ GEM tzinfo (~> 2.0) zeitwerk (~> 2.3) concurrent-ruby (1.1.7) - diff-lcs (1.4.4) + diff-lcs (1.5.1) i18n (1.8.7) concurrent-ruby (~> 1.0) minitest (5.14.3) rake (13.2.1) rexml (3.3.5) strscan - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.0) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.0) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) strscan (3.1.0) tzinfo (2.0.4) concurrent-ruby (~> 1.0)