Class: Command::Remove

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

Instance Method Summary collapse

Methods inherited from CommandBase

execute!, #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 "\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\n  Example:\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\u3059\u308B\n\n  Options:\n  EOS\n  @opt.on(\"-y\", \"--yes\", \"\u524A\u9664\u78BA\u8A8D\u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u8868\u793A\u3057\u306A\u3044\") {\n    @options[\"yes\"] = true\n  }\n  @opt.on(\"-w\", \"--with-file\", \"\u5C0F\u8AAC\u306E\u4FDD\u5B58\u30D5\u30A9\u30EB\u30C0\u30FB\u30D5\u30A1\u30A4\u30EB\u3082\u5168\u3066\u524A\u9664\u3059\u308B\") {\n    @options[\"with-file\"] = true\n  }\n  @opt.on(\"--all-ss\", \"\u77ED\u7DE8\u5C0F\u8AAC\u3092\u3059\u3079\u3066\u524A\u9664\u3059\u308B\") {\n    @options[\"all-ss\"] = true\n  }\nend\n"

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