Class: Vivlio::Starter::CLI::RenameCommandExecutor

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/starter/cli/rename.rb

Overview

章のリネーム・連番付け直しを実行するクラス

使用方法:

RenameCommandExecutor.new(options).call(old_arg, new_arg)
RenameCommandExecutor.new(options).call  # 全章連番付け直し

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RenameCommandExecutor

Returns a new instance of RenameCommandExecutor.

Parameters:

  • options (Hash) (defaults to: {})

    オプション設定

    • :force [Boolean] 確認をスキップ

    • :dry_run [Boolean] 実行せずに変更予定のみ表示

    • :verbose [Boolean] 詳細ログを出力

    • :step [Integer] 章番号の刻み幅(デフォルト: 1)



57
58
59
# File 'lib/vivlio/starter/cli/rename.rb', line 57

def initialize(options = {})
  @options = (options || {}).dup
end

Instance Method Details

#call(old_arg = nil, new_arg = nil) ⇒ void

This method returns an undefined value.

リネーム処理を実行する

Parameters:

  • old_arg (String, nil) (defaults to: nil)

    旧名(nil の場合は全章連番付け直し)

  • new_arg (String, nil) (defaults to: nil)

    新名(nil の場合は全章連番付け直し)

Raises:

  • (SystemExit)

    エラー時または dry-run 完了時



67
68
69
70
71
72
73
74
75
# File 'lib/vivlio/starter/cli/rename.rb', line 67

def call(old_arg = nil, new_arg = nil)
  enable_verbose_mode

  if old_arg.nil? && new_arg.nil?
    renumber_all_chapters
  else
    rename_single_chapter(old_arg, new_arg)
  end
end