Class: Command::Freeze

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CommandBase

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

Constructor Details

#initializeFreeze

Returns a new instance of Freeze.



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/freeze.rb', line 16

def initialize
  super("<target> [<target2> ...] [options]")
  @opt.separator "\n  \u30FB\u6307\u5B9A\u3057\u305F\u5C0F\u8AAC\u3092\u51CD\u7D50\u3057\u3001\u5909\u66F4\u4E0D\u53EF\u5C5E\u6027\u3092\u4ED8\u4E0E\u3057\u307E\u3059\u3002\n  \u30FB\u51CD\u7D50\u3059\u308B\u3053\u3068\u3067\u30C0\u30A6\u30F3\u30ED\u30FC\u30C9\u3001\u30A2\u30C3\u30D7\u30C7\u30FC\u30C8\u53CA\u3073\u524A\u9664\u304C\u51FA\u6765\u306A\u304F\u306A\u308A\u307E\u3059\u3002\n  \u30FB\u51CD\u7D50\u6E08\u307F\u306E\u5C0F\u8AAC\u3092\u6307\u5B9A\u3057\u305F\u5834\u5408\u3001\u51CD\u7D50\u304C\u89E3\u9664\u3055\u308C\u307E\u3059\u3002\n\n  Examples:\nnarou freeze --list\nnarou freeze n9669bk\nnarou freeze 0 1 musyoku\n\n  Options:\n  EOS\n  @opt.on(\"-l\", \"--list\", \"\u51CD\u7D50\u4E2D\u5C0F\u8AAC\u306E\u4E00\u89A7\u3092\u8868\u793A\") {\n    output_freeze_list\n    exit 0\n  }\n  @opt.on(\"--on\", \"\u73FE\u5728\u306E\u72B6\u614B\u306B\u304B\u304B\u308F\u3089\u305A\u51CD\u7D50\u3059\u308B\") {\n    @options[\"on\"] = true\n  }\n  @opt.on(\"--off\", \"\u73FE\u5728\u306E\u72B6\u614B\u306B\u304B\u304B\u308F\u3089\u305A\u89E3\u9664\u3059\u308B\") {\n    @options[\"off\"] = true\n  }\nend\n"

Class Method Details

.oneline_helpObject



12
13
14
# File 'lib/command/freeze.rb', line 12

def self.oneline_help
  "小説の凍結設定を行います"
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
# File 'lib/command/freeze.rb', line 47

def execute(argv)
  super
  if argv.empty?
    puts @opt.help
    return
  end
  tagname_to_ids(argv)
  frozen_list = Inventory.load("freeze")
  argv.each do |target|
    data = Downloader.get_data_by_target(target)
    unless data
      puts "#{target} は存在しません"
      next
    end
    id, title = data["id"], data["title"]
    flag = !frozen_list.include?(id)
    flag = true if @options["on"]
    flag = false if @options["off"]
    if flag
      frozen_list[id] = true
      puts "#{title} を凍結しました"
    else
      frozen_list.delete(id)
      puts "#{title} の凍結を解除しました"
      next
    end
  end
  frozen_list.save
end

#output_freeze_listObject



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

def output_freeze_list
  List.execute!(%w(--filter frozen))
end