jp_quest 0.1.3 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35e9ce08dc713c11e7972f330006d8af55906971876cad0d5747a20231734b41
4
- data.tar.gz: cb2f5ff1a82825de5d6710783d24b66543ceaa83a0430cef85b603d1cd71e795
3
+ metadata.gz: d0c36a1f3e9e85ef6e690ec96ddbb36391efe55d9d996490a5905c0d7dc98c15
4
+ data.tar.gz: 66555ea8f531ae8ac001f97d852b4f38797e4e3d38db294f1804fdbc76cb901b
5
5
  SHA512:
6
- metadata.gz: 6b2d660043bf3c6066784cf78f420396ee65652bf898135208520f8d85a45e277cf1f049c5ebb3d18385310722ac59d901a0e2e5f8a20dcefdefa96fe4c18702
7
- data.tar.gz: 8520014fd3d5c4ac62c372613e2f0e7038b149770e8c8ddcc18f1109b97777ec2f756e4388926922d6eb80321520d1be3813edb417f4a0aefe24e226d7a426f8
6
+ metadata.gz: a3011529e8f7a2b4808223fd3bcfaf4c078f56ca637748d3fbd33eb226aebf07cfafd2d2654591ea56ca5a2e6069e0ecc5d691db72d4570465d5763a5ff4169a
7
+ data.tar.gz: 63ee1e3a2ee419b72654a2cd87fec57e1e8eb2cbf26c93114347de58fa5e0874d5b9c91e833fab740b84c40216751d48d1e30bf552ba3253cf785f4ed51586a4
data/.rubocop.yml CHANGED
@@ -1,8 +1,6 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 3.0
3
3
  NewCops: enable
4
- Exclude:
5
- - "bin/**/*"
6
4
 
7
5
  Style/StringLiterals:
8
6
  EnforcedStyle: double_quotes
data/CHANGELOG.md CHANGED
@@ -14,4 +14,9 @@
14
14
 
15
15
  ## [0.1.3] - 2024-10/8
16
16
 
17
- - バグ修正
17
+ - バグ修正
18
+
19
+ ## [0.2.0] - 2024-10/9
20
+
21
+ - 出力時のダブルクオート数、インデント数が崩れていたのを出来るだけ抑制
22
+ - quests.snbtのパス名も変換されていたのを修正
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## JpQuest
2
2
 
3
- Translator for `.snbt` files. (title, subtitle, description)
3
+ Translator for FTBQuest. (title, subtitle, description)
4
4
  If you want to translate to other languages than Japanese,
5
5
  please add the `exchange_language` option during initialization.
6
6
  Can always get help with `JpQuest.help`
@@ -15,7 +15,7 @@ Can always get help with `JpQuest.help`
15
15
  2. Make `.env` file
16
16
  3. Add `OPENAI_API_KEY=your_api_key` to `.env`
17
17
  4. Optional: Add `OPENAI_MODEL=some_openai_model` to `.env` **(default: gpt-4o-mini)**
18
- 5. Add `some.snbt` to `quests` directory
18
+ 5. Add `some.snbt` or `quests` directory contents to `quests` directory
19
19
  6. Check `output` directory
20
20
 
21
21
  ## Initialize Options
@@ -38,4 +38,4 @@ Which language do you want to translate to?
38
38
  #### display_help
39
39
 
40
40
  Want to display help?
41
- **(default: true)**
41
+ **(default: true)**
data/dist/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "jp_quest", "~> 0.1.3"
3
+ gem "jp_quest"
data/dist/example.rb CHANGED
@@ -1,8 +1,8 @@
1
- require_relative "../lib/jp_quest"
1
+ require "jp_quest"
2
2
 
3
3
  performer = JpQuest::Performer.new
4
4
 
5
5
  # file_path = "some.snbt"
6
6
  # performer.perform(file_path)
7
7
 
8
- performer.perform_directory
8
+ performer.perform_directory(dir_path: "dist/quests")
@@ -11,53 +11,70 @@ module JpQuest
11
11
  # @param [String] indent インデント
12
12
  # @return [String] SNBT形式に整形したコンテンツ
13
13
  def format_overwritable_lines(content, indent)
14
- mid_indent = middle_indent(content[:indent])
15
- indented_lines = add_indent_for_middle_lines(content, mid_indent)
16
- formatted_lines = add_missing_lines(indented_lines, content, mid_indent)
17
- format_for_snbt(formatted_lines, indent, content[:type])
14
+ full_lines = add_missing_lines(content)
15
+ format_for_snbt(full_lines, indent, content)
18
16
  end
19
17
 
20
18
  # SNBT形式に整形
21
19
  #
22
20
  # @param [Array<String>] lines 行
23
21
  # @param [String] indent インデント
24
- # @param [Symbol] type コンテンツの種類
22
+ # @param [Hash] content コンテンツ
25
23
  # @return [String] SNBT形式に整形した行
26
- def format_for_snbt(lines, indent, type)
27
- lines.map! { |line| delete_quotes(line) }
28
- lines.map!(&:strip) unless type == :description
29
-
30
- formatted_lines =
31
- if lines.length == 1
32
- type == :description ? "[#{lines[0].strip}]" : lines[0].strip.to_s
33
- else
34
- # description: [
35
- # "Hello"
36
- # "World"
37
- # ]
38
- "[\n#{lines.join("\n")}\n#{indent}]"
39
- end
40
-
41
- # " description: ["hoge"]"のような形式にする
42
- "#{indent}#{type}: #{formatted_lines}"
24
+ def format_for_snbt(lines, indent, content)
25
+ lines = prepare_lines_for_snbt(lines, content)
26
+ formatted_lines = format_lines(lines, indent, content)
27
+ "#{indent}#{content[:type]}: #{formatted_lines}"
43
28
  end
44
29
 
45
30
  # 不足している行を追加
46
31
  #
47
- # @param [Array<String>] lines 行
48
32
  # @param [Hash] content コンテンツ
49
- # @param [String] middle_indent 中間行のインデント
50
33
  # @return [void]
51
- def add_missing_lines(lines, content, middle_indent)
34
+ def add_missing_lines(content)
52
35
  required_lines = extract_required_line_counts(content)
36
+ lines = content[:text].split("\n")
53
37
 
54
38
  while lines.length < required_lines
55
- lines << empty_middle_line(middle_indent)
39
+ lines << empty_middle_line(content[:indent])
56
40
  end
57
41
 
58
42
  lines
59
43
  end
60
44
 
45
+ private
46
+
47
+ # 不要な文字を削除する
48
+ #
49
+ # @param [String] lines 行
50
+ # @param [Hash] content コンテンツ
51
+ # @return [Array<String>] 不要な文字を削除した行
52
+ def prepare_lines_for_snbt(lines, content)
53
+ lines.map! { |line| delete_unwanted_symbols(line) }
54
+ lines.map!(&:strip) unless content[:type] == :description
55
+ lines
56
+ end
57
+
58
+ # SNBT形式に変換しやすい形に整形
59
+ #
60
+ # @param [Array<String>] lines 行
61
+ # @param [String] indent インデント
62
+ # @param [Hash] content コンテンツ
63
+ # @return [String] SNBT形式に変換しやすく整形した行
64
+ def format_lines(lines, indent, content)
65
+ if lines.length == 1
66
+ content[:type] == :description ? "[#{lines[0].strip}]" : lines[0].strip.to_s
67
+ else
68
+ # [
69
+ # "Hello"
70
+ # "World"
71
+ # ]
72
+ mid_indent = middle_indent(content[:indent])
73
+ lines = lines.map { |line| "#{mid_indent}#{line.strip}" }
74
+ "[\n#{lines.join("\n")}\n#{indent}]"
75
+ end
76
+ end
77
+
61
78
  # 必要な行数を抽出
62
79
  #
63
80
  # @param [Hash] content コンテンツ
@@ -70,62 +87,52 @@ module JpQuest
70
87
  (content[:end_line] - content[:start_line]) + line_offset - without_brackets
71
88
  end
72
89
 
73
- # 中間行のインデントを追加
74
- #
75
- # @param [Hash] content コンテンツ
76
- # @param [String] middle_indent 中間行のインデント
77
- # @return [Array<String>] 中間行のインデントを追加した行
78
- def add_indent_for_middle_lines(content, middle_indent)
79
- content[:text].split("\n").map do |line|
80
- "#{middle_indent}\"#{line}\""
81
- end
82
- end
83
-
84
90
  # 中間行の空行を作成
85
91
  #
86
- # @param [String] middle_indent 中間行のインデント
87
92
  # @return [String] 空行
88
- def empty_middle_line(middle_indent)
89
- "#{middle_indent}\"\""
93
+ def empty_middle_line(indent)
94
+ middle_indent(indent).to_s
90
95
  end
91
96
 
92
- # 不要な引用符を削除
97
+ # 不要な記号を削除
93
98
  #
94
99
  # @param [String] line 行
95
- # @return [String] 不要な引用符を削除した行
96
- def delete_quotes(line)
100
+ # @return [String] 不要な記号を削除した行
101
+ def delete_unwanted_symbols(line)
102
+ line = delete_backslash(line)
103
+ line = delete_semicolon(line)
97
104
  line = delete_dup_quotes(line)
98
105
  line = delete_jp_quotes(line)
99
106
  delete_curved_quotes(line)
100
107
  end
101
108
 
102
- private
109
+ # 不要なバックスラッシュを削除
110
+ #
111
+ # @param [String] line 行
112
+ # @return [String] 不要なバックスラッシュを削除した行
113
+ def delete_backslash(line)
114
+ line.gsub("\\", "")
115
+ end
116
+
117
+ # 不要なセミコロンを削除
118
+ #
119
+ # @param [String] line 行
120
+ # @return [String] 不要なセミコロンを削除した行
121
+ def delete_semicolon(line)
122
+ line.gsub(";", "")
123
+ end
103
124
 
104
125
  # 不要なダブルクオートを削除
105
126
  #
106
127
  # @param [String] line 行
107
128
  # @return [String] 不要なダブルクオートを削除した行
108
129
  def delete_dup_quotes(line)
109
- # ""Hello""、""""
110
- deletable_regs = [/"{2,}.+".*"/, /"{3,}/]
111
- return line unless deletable_regs.any? { |reg| line.match?(reg) }
112
-
113
- # ""
114
- dup_reg = /"{2,}/
115
- # """"に一致する場合は空白行なので、""に変換する
116
- if line.strip.match?(deletable_regs[1])
117
- line.gsub(dup_reg, '""')
118
- else
119
- # 行間にある余計なダブルクオートを削除するため、一度全てのダブルクオートを削除している
120
- line = line.gsub('"', "")
121
- # インデントの調整
122
- indent_count = normalize_indent(line[/^\s*/].length)
123
- line_start = /^(\s*)/
124
- # 行頭にインデントとダブルクオートを追加
125
- line = line.sub(line_start, "#{" " * indent_count}\"")
126
- # 行末のダブルクオートを追加
127
- "#{line}\""
128
- end
130
+ # 行間にある余計なダブルクオートを削除するため、一度全てのダブルクオートを削除している
131
+ # 全て削除したあと、行頭、行末にダブルクオートを追加する
132
+ line = line.gsub('"', "")
133
+ line_start = /^(\s*)/
134
+ line = line.sub(line_start, "\"")
135
+ "#{line}\""
129
136
  end
130
137
 
131
138
  # 不要な鍵括弧を削除
@@ -16,21 +16,5 @@ module JpQuest
16
16
  def middle_indent(indent)
17
17
  " " * (indent + 1)
18
18
  end
19
-
20
- # インデントを調整
21
- #
22
- # @param [Integer] indent インデント数
23
- # @return [Integer] 調整後のインデント数
24
- def normalize_indent(indent)
25
- dup_indent = 12
26
- if indent > dup_indent
27
- half = 2
28
- half_indent = indent / half
29
- # インデントの数は偶数にする
30
- half_indent.even? ? half_indent : half_indent + 1
31
- else
32
- indent
33
- end
34
- end
35
19
  end
36
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JpQuest
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.1"
5
5
  end
@@ -11,7 +11,8 @@ module JpQuest
11
11
  # @return [JpQuest::Writer]
12
12
  def initialize(file_path)
13
13
  @input_file_path = file_path
14
- @output_file_path = file_path.gsub("quests", "output/quests")
14
+ # questsとすると、quests.snbtも変換されてしまうので、quests/とする
15
+ @output_file_path = file_path.gsub("quests/", "output/quests/")
15
16
  @formatter = JpQuest::Formatter.new
16
17
  end
17
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jp_quest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - milkeclair
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-08 00:00:00.000000000 Z
11
+ date: 2024-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jp_translator_from_gpt
@@ -91,7 +91,7 @@ metadata:
91
91
  source_code_uri: https://github.com/milkeclair/jp_quest/blob/main
92
92
  changelog_uri: https://github.com/milkeclair/jp_quest/blob/main/CHANGELOG.md
93
93
  rubygems_mfa_required: 'true'
94
- post_install_message:
94
+ post_install_message:
95
95
  rdoc_options: []
96
96
  require_paths:
97
97
  - lib
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  version: '0'
108
108
  requirements: []
109
109
  rubygems_version: 3.5.21
110
- signing_key:
110
+ signing_key:
111
111
  specification_version: 4
112
112
  summary: translate to japanese for ftbquest
113
113
  test_files: []