Class: Command::Remove

Inherits:
CommandBase show all
Defined in:
lib/command/remove.rb

Instance Method Summary collapse

Methods inherited from CommandBase

execute_and_rescue_exit, #load_local_settings

Constructor Details

#initializeRemove

Returns a new instance of Remove.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/command/remove.rb', line 11

def initialize
  super("<target> [<target2> ...] [options]")
  @opt.separator <<-EOS

  ・削除したい小説のNコード、URL、タイトルもしくはIDを指定して下さい。
IDは #{@opt.program_name} list を参照して下さい。
  ・一度に複数の小説を指定する場合は空白で区切って下さい。
  ・削除確認をスキップするには -y オプションを有効にして下さい。
  ・削除するのはデータベースのインデックスだけで、変換済みテキストファイルやMOBIファイル等はそのまま残ります。ファイルをすべて削除する場合は --with-file オプションを指定して下さい。

  Example:
narou remove n9669bk
narou remove http://ncode.syosetu.com/n9669bk/
narou remove n9669bk http://ncode.syosetu.com/n4259s/
narou remove 0 1 -y
narou remove n9669bk --with-file   # ファイルも完全に削除する
narou remove --all-ss              # 連載小説をすべて削除する
narou remove --all-ss --with-file  # 短編小説をファイルも含めてすべて削除する

  Options:
  EOS
  @opt.on("-y", "--yes", "削除確認メッセージを表示しない") {
    @options["yes"] = true
  }
  @opt.on("--with-file", "小説の保存フォルダ・ファイルも全て削除する") {
    @options["with-file"] = true
  }
  @opt.on("--all-ss", "短編小説をすべて削除する") {
    @options["all-ss"] = true
  }
end

Instance Method Details

#execute(argv) ⇒ Object



47
48
49
50
51
52
53
54
55
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
# File 'lib/command/remove.rb', line 47

def execute(argv)
  super
  novels = []
  if @options["all-ss"]
    novels = get_all_short_story
    if novels.count == 0
      puts "短編小説がひとつもありません"
      return
    end
    argv += novels.map { |n| n["id"].to_s }
  end
  if argv.empty?
    puts @opt.help
    return
  end
  argv.each_with_index do |target, i|
    Helper.print_horizontal_rule if i > 0
    data = Downloader.get_data_by_target(target)
    unless data
      error "#{target} は存在しません"
      next
    end
    title = data["title"]
    if Narou.novel_frozen?(target)
      puts "#{title} は凍結中です\n削除を中止しました"
      next
    end
    unless @options["yes"]
      next unless Helper.confirm("#{title}#{(@options["with-file"] ? "“完全に”" : "")}削除しますか")
    end
    Downloader.remove_novel(target, @options["with-file"])
    puts "<green>#{TermColor.escape(title)} を削除しました</green>".termcolor
  end
end

#get_all_short_storyObject



43
44
45
# File 'lib/command/remove.rb', line 43

def get_all_short_story
  Database.instance.get_object.values.select { |v| v["novel_type"] == 2 }
end

#oneline_helpObject



82
83
84
# File 'lib/command/remove.rb', line 82

def oneline_help
  "小説を削除します"
end