Class: Command::Remove

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

Instance Attribute Summary

Attributes inherited from CommandBase

#stream_io

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandBase

#disable_logging, #display_help!, execute!, #execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids

Constructor Details

#initializeRemove

Returns a new instance of Remove.



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
42
43
44
45
46
47
48
# File 'lib/command/remove.rb', line 17

def initialize
  super("<target> [<target2> ...] [options]")
  @opt.separator "\n\u30FB\u524A\u9664\u3057\u305F\u3044\u5C0F\u8AAC\u306EN\u30B3\u30FC\u30C9\u3001URL\u3001\u30BF\u30A4\u30C8\u30EB\u3082\u3057\u304F\u306FID\u3092\u6307\u5B9A\u3057\u3066\u4E0B\u3055\u3044\u3002\nID\u306F \#{@opt.program_name} list \u3092\u53C2\u7167\u3057\u3066\u4E0B\u3055\u3044\u3002\n\u30FB\u4E00\u5EA6\u306B\u8907\u6570\u306E\u5C0F\u8AAC\u3092\u6307\u5B9A\u3059\u308B\u5834\u5408\u306F\u7A7A\u767D\u3067\u533A\u5207\u3063\u3066\u4E0B\u3055\u3044\u3002\n\u30FB\u524A\u9664\u78BA\u8A8D\u3092\u30B9\u30AD\u30C3\u30D7\u3059\u308B\u306B\u306F -y \u30AA\u30D7\u30B7\u30E7\u30F3\u3092\u6709\u52B9\u306B\u3057\u3066\u4E0B\u3055\u3044\u3002\n\u30FB\u524A\u9664\u3059\u308B\u306E\u306F\u30C7\u30FC\u30BF\u30D9\u30FC\u30B9\u306E\u30A4\u30F3\u30C7\u30C3\u30AF\u30B9\u3060\u3051\u3067\u3001\u5909\u63DB\u6E08\u307F\u30C6\u30AD\u30B9\u30C8\u30D5\u30A1\u30A4\u30EB\u3084MOBI\u30D5\u30A1\u30A4\u30EB\u7B49\u306F\u305D\u306E\u307E\u307E\u6B8B\u308A\u307E\u3059\u3002\u30D5\u30A1\u30A4\u30EB\u3092\u3059\u3079\u3066\u524A\u9664\u3059\u308B\u5834\u5408\u306F --with-file \u30AA\u30D7\u30B7\u30E7\u30F3\u3092\u6307\u5B9A\u3057\u3066\u4E0B\u3055\u3044\u3002\n\nExamples:\nnarou remove n9669bk\nnarou remove http://ncode.syosetu.com/n9669bk/\nnarou remove n9669bk http://ncode.syosetu.com/n4259s/\nnarou remove 0 1 -y\nnarou remove n9669bk --with-file   # \u30D5\u30A1\u30A4\u30EB\u3082\u5B8C\u5168\u306B\u524A\u9664\u3059\u308B\nnarou remove --all-ss              # \u9023\u8F09\u5C0F\u8AAC\u3092\u3059\u3079\u3066\u524A\u9664\u3059\u308B\nnarou remove --all-ss --with-file  # \u77ED\u7DE8\u5C0F\u8AAC\u3092\u30D5\u30A1\u30A4\u30EB\u3082\u542B\u3081\u3066\u3059\u3079\u3066\u524A\u9664\nnarou r 0 -wy    # ID:0\u3092\u78BA\u8A8D\u30E1\u30C3\u30BB\u30FC\u30B8\u306A\u3057\u306B\u30D5\u30A1\u30A4\u30EB\u3082\u542B\u3081\u3066\u5B8C\u5168\u306B\u524A\u9664\u3059\u308B\n\nOptions:\n"
  @opt.on("-y", "--yes", "削除確認メッセージを表示しない") {
    @options["yes"] = true
  }
  @opt.on("-w", "--with-file", "小説の保存フォルダ・ファイルも全て削除する") {
    @options["with-file"] = true
  }
  @opt.on("--all-ss", "短編小説をすべて削除する") {
    @options["all-ss"] = true
  }
end

Class Method Details

.oneline_helpObject



13
14
15
# File 'lib/command/remove.rb', line 13

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

Instance Method Details

#execute(argv) ⇒ Object



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
81
82
83
84
85
86
87
# File 'lib/command/remove.rb', line 54

def execute(argv)
  super
  if @options["all-ss"]
    novels = get_all_short_story
    if novels.size == 0
      puts "短編小説がひとつもありません"
      return
    end
    argv += novels.map { |n| n["id"].to_s }
  end
  display_help! if argv.empty?
  tagname_to_ids(argv)
  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.locked?(target)
      error "#{title} は変換中なため削除出来ませんでした"
      next
    elsif Narou.novel_frozen?(target)
      puts "#{title} は凍結中です\n削除を中止しました"
      next
    end
    unless @options["yes"]
      next unless Narou::Input.confirm("#{title} を#{(@options["with-file"] ? "“完全に”" : "")}削除しますか")
    end
    Downloader.remove_novel(target, @options["with-file"])
    puts "<bold><green>#{TermColorLight.escape(title)} を削除しました</green></bold>".termcolor
  end
end

#get_all_short_storyObject



50
51
52
# File 'lib/command/remove.rb', line 50

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