Class: VivlioStarter::CLI::SamovarCommands::ResizeCommand
- Inherits:
-
VsCommand
- Object
- Samovar::Command
- VsCommand
- VivlioStarter::CLI::SamovarCommands::ResizeCommand
- Defined in:
- lib/vivlio_starter/cli/samovar/resize_command.rb
Overview
resize コマンドの Samovar 実装
Constant Summary
Constants included from OptionTokenNormalizer
OptionTokenNormalizer::BARE_VALUE_DEFAULTS
Class Method Summary collapse
-
.preset_help(label, preset_name, note: nil) ⇒ Object
プリセットの説明を
WEBP_PRESETSから組む。.
Instance Method Summary collapse
Methods included from OptionTokenNormalizer
Class Method Details
.preset_help(label, preset_name, note: nil) ⇒ Object
プリセットの説明を WEBP_PRESETS から組む。
数値をヘルプに書き写してはならない。 プリセットを動かしたときに黙って
食い違う——--high の上限は 2026-08-17 に 2000 → 2048 へ変えたばかりで、
そのとき原稿の 2 箇所も追いかけて直す必要があった。ここは正典を 1 つに保つ。
39 40 41 42 43 |
# File 'lib/vivlio_starter/cli/samovar/resize_command.rb', line 39 def self.preset_help(label, preset_name, note: nil) preset = ResizeCommands::WEBP_PRESETS.fetch(preset_name) parts = ["quality=#{preset[:quality]}", "最大 #{preset[:max_px]}px", note].compact "#{label}(#{parts.join(' / ')})" end |
Instance Method Details
#call ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/vivlio_starter/cli/samovar/resize_command.rb', line 56 def call # --help が未定義だと位置引数 dir に「--help」が落ちてしまう(契約テスト CL-01 で検出) if [:help] print_usage return 0 end # 前提条件の検証(ProjectRoot ◎ / ImagesDir ◎) # 既定の images/ 以外を対象にする場合(vs resize <dir>)は ImagesDir を検証しない checks = [Guards::ProjectRootCheck.new] checks << Guards::ImagesDirCheck.new if resolve_dir == Common::IMAGES_DIR guard_failure = Guards.precheck(*checks) return guard_failure if guard_failure # --medium は既定と同じだが、受け付ける。3 つのプリセットが原稿の表に並んでいるのに # 「標準だけはオプションで書けない」のは著者を戸惑わせる(実際に問われた)。 preset = if [:high] '高精細' elsif [:low] '軽量' else '標準' end report_result(ResizeCommands.execute_resize_with_preset(preset, resolve_dir, )) 0 end |