copy_tuner_incompatible_search 2.0.2 → 2.0.3

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
  SHA256:
3
- metadata.gz: 1d8e36a8c2fe00fe286e5c1ddead546acc1f5b697798c8c62474f01905e95358
4
- data.tar.gz: bbd8ecb9ca27bad1a3270653d2a2288c58235a00644262e57cce53faea3c799d
3
+ metadata.gz: 549e35e731fc1cc494c260d49c66e5dcdb5db7eb4cb4a82bd5dad34f32f2a685
4
+ data.tar.gz: 14e23c9d6841ccb3e18b49de84daa2a16c52a1c84f522d0bb121e3a31492945b
5
5
  SHA512:
6
- metadata.gz: f065e961d42ecc2ada50b12700a0511ec81259b943e76a33891beead260f1daa2e54c5bc67f930c5af383c2a02b5334554c577b3114340b91301aa1ce5022693
7
- data.tar.gz: e9fa13e7a77be62c0a9a04ec55cc0ecebfc6696f618e638659ab7386689e78adc687c266ecd86a7a7cba8c8faab153fb49b9413f36582f7f355f6b39bf1349ec
6
+ metadata.gz: 4967fec81fb7dc9cadb284f979cd85874fa5c1412f3ed9a1cdcd421d79534e8b1d860f1af348d89e8758a76c04d3c66469443b56cced0492f3965e134596236b
7
+ data.tar.gz: dba034921fafca23d9762a18ee0ef2df043f528307891e203976e10368b4c4b36ce954c08ec845cb5781f7a978f5a1fd68a6b0ffa4cc68af1c1242e7120f2307
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
- ## [Unreleased]
1
+ ## [Unreleased]o
2
+ ## [2.0.3] - 2024-07-03
3
+ - Bug fix
4
+
2
5
  ## [2.0.2] - 2024-05-04
3
6
  - Consider BOM in blurbs.csv
4
7
  ## [2.0.1] - 2024-05-04
data/Steepfile CHANGED
@@ -29,7 +29,5 @@
29
29
  # end
30
30
  target :lib do
31
31
  check 'lib'
32
- # すぐにrbsを導入するのは難しそうなのであとまわし
33
- ignore 'lib/copy_tuner_incompatible_search/replace_command.rb'
34
32
  signature 'sig'
35
33
  end
@@ -5,6 +5,6 @@ require_relative '../lib/copy_tuner_incompatible_search'
5
5
  project_name = File.basename(Dir.pwd)
6
6
  timestamp = Time.now.strftime('%Y%m%d%H%M%S')
7
7
  output_path = "tmp/usages-#{project_name}-#{timestamp}.xlsx"
8
- CopyTunerIncompatibleSearch::Command.run(output_path)
8
+ CopyTunerIncompatibleSearch::SearchCommand.run(output_path)
9
9
  puts "open #{output_path}"
10
10
  `open #{output_path}`
@@ -18,10 +18,10 @@ module CopyTunerIncompatibleSearch
18
18
 
19
19
  def run(output_path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
20
20
  # usages.xlsxから生成したUsageオブジェクトの配列
21
- usages = usage_sheet.each(type: 'Type', key: 'Key', ignored: 'Ignored', file: 'File', line: 'Line').filter_map.with_index do |hash, i|
21
+ usages = usage_sheet.each(type: 'Type', key: 'Key', file: 'File', line: 'Line').filter_map.with_index do |hash, i|
22
22
  next if i.zero? # skip header
23
23
 
24
- Usage.new(**hash)
24
+ Usage.new(type: hash[:type], key: hash[:key], file: hash[:file], line: hash[:line])
25
25
  end
26
26
  # プロジェクト内で後方互換性のないキーの集合
27
27
  incompatible_keys = Set[*usages.select(&:static?).map(&:key)]
@@ -53,7 +53,7 @@ module CopyTunerIncompatibleSearch
53
53
  if i.zero?
54
54
  csv_out << row.headers
55
55
  end
56
- key = row[0]
56
+ key = row['key']
57
57
  converted_key = "#{key}_html"
58
58
  if keys_to_convert.include?(key) && !dot_converted_keys.include?(key) && !underscore_converted_keys.include?(key)
59
59
  csv_out << [converted_key, *row[1..]]
@@ -82,14 +82,13 @@ module CopyTunerIncompatibleSearch
82
82
  attr_reader :usage_path, :blurbs_path
83
83
 
84
84
  class Usage
85
- attr_reader :type, :key, :file, :line
85
+ attr_reader :type, :key, :file
86
86
 
87
- def initialize(type:, key:, ignored:, file:, line:)
87
+ def initialize(type:, key:, file:, line:)
88
88
  @type = type
89
- @key = key
90
- @ignored = ignored
91
- @file = file
92
- @line = line.to_s.empty? ? nil : line.to_i
89
+ @key = key.to_s
90
+ @file = file.to_s
91
+ @line = line.to_s
93
92
  end
94
93
 
95
94
  def static?
@@ -114,6 +113,12 @@ module CopyTunerIncompatibleSearch
114
113
  last_key = key.split('.').last
115
114
  ".#{last_key}"
116
115
  end
116
+
117
+ def line
118
+ raise 'line is not set' if @line.empty?
119
+
120
+ @line.to_i
121
+ end
117
122
  end
118
123
 
119
124
  class Result
@@ -154,7 +159,8 @@ module CopyTunerIncompatibleSearch
154
159
  CSV.parse(blurbs_csv_text, headers: true, quote_char: '"').each do |row|
155
160
  key = row['key']
156
161
  all_blurb_keys << key
157
- translation = row[1]
162
+ tr_range = detect_translation_range(row)
163
+ translation = row[tr_range].join(' ')
158
164
  if translation.match?(/&#\d+;|&\w+;/) && !key.match?(/[_.]html$/)
159
165
  keys_with_special_chars << key
160
166
  end
@@ -162,6 +168,12 @@ module CopyTunerIncompatibleSearch
162
168
  [Set[*all_blurb_keys], keys_with_special_chars]
163
169
  end
164
170
 
171
+ def detect_translation_range(row)
172
+ start = 1
173
+ finish = row.to_h.keys.index('created_at') - 1
174
+ start..finish
175
+ end
176
+
165
177
  def replace_code_for_lazy_usages(lazy_usages_by_key, keys_for_code_replace, underscore_converted_keys, dot_converted_keys)
166
178
  lazy_usages_by_key.each do |key, usages|
167
179
  next unless keys_for_code_replace.include?(key)
@@ -186,7 +198,7 @@ module CopyTunerIncompatibleSearch
186
198
  lines = file_readlines(usage.file)
187
199
  if usage.lazy?
188
200
  lazy_key = usage.lazy_key
189
- regex = /(?<=['"])#{Regexp.escape(lazy_key)}(?=['"])/
201
+ regex = /(?<=['"])#{Regexp.escape(lazy_key.to_s)}(?=['"])/
190
202
  else
191
203
  regex = /(?<=['"])#{Regexp.escape(usage.key)}(?=['"])/
192
204
  end
@@ -4,7 +4,7 @@ require 'axlsx'
4
4
  require 'set'
5
5
 
6
6
  module CopyTunerIncompatibleSearch
7
- class Command
7
+ class SearchCommand
8
8
  def self.run(output_path)
9
9
  self.new.run(output_path)
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CopyTunerIncompatibleSearch
4
- VERSION = '2.0.2'
4
+ VERSION = '2.0.3'
5
5
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'copy_tuner_incompatible_search/version'
4
- require_relative 'copy_tuner_incompatible_search/command'
4
+ require_relative 'copy_tuner_incompatible_search/search_command'
5
5
  require_relative 'copy_tuner_incompatible_search/xlsx_writer'
6
6
  require_relative 'copy_tuner_incompatible_search/replace_command'
7
7
 
@@ -0,0 +1,100 @@
1
+ module CopyTunerIncompatibleSearch
2
+ class ReplaceCommand
3
+ def self.run: (String usage_path, String blurbs_path, String output_path) -> void
4
+
5
+ def initialize: (String usage_path, String blurbs_path) -> void
6
+
7
+ def run: (String output_path) -> Result
8
+
9
+ private
10
+
11
+ attr_reader usage_path: String
12
+
13
+ attr_reader blurbs_path: String
14
+
15
+ class Usage
16
+ @line: String
17
+
18
+ type usage_type = 'dynamic' | 'static' | 'lazy'
19
+
20
+ attr_reader type: usage_type
21
+
22
+ attr_reader key: String
23
+
24
+ attr_reader file: String
25
+
26
+ def initialize: (type: usage_type, key: String?, file: String?, line: String?) -> void
27
+
28
+ def static?: () -> bool
29
+
30
+ def lazy?: () -> bool
31
+
32
+ def dynamic?: () -> bool
33
+
34
+ def used?: () -> bool
35
+
36
+ def lazy_key: () -> (nil | String)
37
+
38
+ def line: () -> Integer
39
+ end
40
+
41
+ class Result
42
+ attr_reader newly_replaced_keys: Array[String]
43
+
44
+ attr_reader existing_keys: Array[String]
45
+
46
+ attr_reader not_used_incompatible_keys: Array[String]
47
+
48
+ attr_reader keys_to_ignore: Array[String]
49
+
50
+ attr_reader already_ignored_keys: Array[String]
51
+
52
+ attr_reader keys_with_special_chars: Array[String]
53
+
54
+ attr_reader dynamic_count: Integer
55
+
56
+ def initialize: (Array[String] newly_replaced_keys, Array[String] existing_keys, Array[String] not_used_incompatible_keys, Array[String] keys_to_ignore, Array[String] already_ignored_keys, Array[String] keys_with_special_chars, Integer dynamic_count) -> void
57
+ end
58
+
59
+ def usage_sheet: () -> untyped
60
+
61
+ def blurbs_csv_text: () -> String
62
+
63
+ def search_ignored_keys: () -> Array[String]
64
+
65
+ def ignored_keys_text: () -> String
66
+
67
+ def parse_blurbs_csv: () -> [Set[String], Array[String]]
68
+
69
+ def replace_code_for_lazy_usages: (Hash[String, Array[Usage]] lazy_usages_by_key, Array[String] keys_for_code_replace, Set[String] underscore_converted_keys, Set[String] dot_converted_keys) -> void
70
+
71
+ def replace_code_for_static_usages: (Hash[String, Array[Usage]] static_usages_by_key, Array[String] keys_for_code_replace, Set[String] underscore_converted_keys, Set[String] dot_converted_keys) -> void
72
+
73
+ def replace_code: (Usage usage, Set[String] underscore_converted_keys, Set[String] dot_converted_keys) -> void
74
+
75
+ def file_readlines: (String path) -> Array[String]
76
+
77
+ def file_write: (String path, String text) -> void
78
+
79
+ def generate_html_key: (Usage usage, Set[String] underscore_converted_keys, Set[String] dot_converted_keys) -> String
80
+ end
81
+ end
82
+
83
+ module Roo
84
+ class Spreadsheet
85
+ def self.open: (String path) -> untyped
86
+ end
87
+ end
88
+
89
+ # 公式のrbsファイルだとなぜかエラーが出てsteep checkがパスしないので、自前で定義している
90
+ class CSV
91
+ def self.parse: (String str, ?::Hash[Symbol, untyped] options) -> Array[CSV::Row]
92
+ def self.open: (String path, String mode) { (CSV csv) -> void } -> void
93
+ def <<: (Array[untyped] row) -> void
94
+ class Row
95
+ def []: (String key) -> String
96
+ | (Integer index) -> String
97
+ | (range[Integer] range) -> Array[String]
98
+ def headers: () -> Array[String]
99
+ end
100
+ end
@@ -1,5 +1,5 @@
1
1
  module CopyTunerIncompatibleSearch
2
- class Command
2
+ class SearchCommand
3
3
  def self.run: (String output_path) -> void
4
4
 
5
5
  def run: (String output_path) -> void
@@ -1,12 +1,12 @@
1
1
  module CopyTunerIncompatibleSearch
2
2
  class XlsxWriter
3
- def initialize: (Array[Command::Result] results, Set[String] incompatible_keys, Set[String] ignored_keys) -> void
3
+ def initialize: (Array[SearchCommand::Result] results, Set[String] incompatible_keys, Set[String] ignored_keys) -> void
4
4
 
5
5
  def save_to: (String output_path) -> void
6
6
 
7
7
  private
8
8
 
9
- attr_reader results: Array[Command::Result]
9
+ attr_reader results: Array[SearchCommand::Result]
10
10
 
11
11
  attr_reader incompatible_keys: Set[String]
12
12
 
@@ -14,9 +14,9 @@ module CopyTunerIncompatibleSearch
14
14
 
15
15
  def freeze_pane: (untyped sheet) -> void
16
16
 
17
- def add_result_rows: (untyped sheet, Command::Result result, untyped style) -> void
17
+ def add_result_rows: (untyped sheet, SearchCommand::Result result, untyped style) -> void
18
18
 
19
- def should_output?: (Command::Usage usage, Command::Result result, String full_key) -> bool
19
+ def should_output?: (SearchCommand::Usage usage, SearchCommand::Result result, String full_key) -> bool
20
20
 
21
21
  def ignored_flag: (String key) -> ("Y" | "N")
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: copy_tuner_incompatible_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Junichi Ito
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-03 00:00:00.000000000 Z
11
+ date: 2024-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: caxlsx
@@ -44,12 +44,13 @@ files:
44
44
  - exe/copy_tuner_incompatible_replace
45
45
  - exe/copy_tuner_incompatible_search
46
46
  - lib/copy_tuner_incompatible_search.rb
47
- - lib/copy_tuner_incompatible_search/command.rb
48
47
  - lib/copy_tuner_incompatible_search/replace_command.rb
48
+ - lib/copy_tuner_incompatible_search/search_command.rb
49
49
  - lib/copy_tuner_incompatible_search/version.rb
50
50
  - lib/copy_tuner_incompatible_search/xlsx_writer.rb
51
51
  - sig/copy_tuner_incompatible_search.rbs
52
- - sig/lib/copy_tuner_incompatible_search/command.rbs
52
+ - sig/lib/copy_tuner_incompatible_search/replace_command.rbs
53
+ - sig/lib/copy_tuner_incompatible_search/search_command.rbs
53
54
  - sig/lib/copy_tuner_incompatible_search/xlsx_writer.rbs
54
55
  homepage: https://github.com/JunichiIto/copy_tuner_incompatible_search
55
56
  licenses:
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  - !ruby/object:Gem::Version
75
76
  version: '0'
76
77
  requirements: []
77
- rubygems_version: 3.5.9
78
+ rubygems_version: 3.5.11
78
79
  signing_key:
79
80
  specification_version: 4
80
81
  summary: Search usage of incompatible keys in CopyTuner.