Class: Command::Update

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

Instance Method Summary collapse

Methods inherited from CommandBase

execute_and_rescue_exit

Constructor Details

#initializeUpdate



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/command/update.rb', line 11

def initialize
  super("[<target> <target2> ...] [option]")
  @opt.separator "\n  \u30FB\u7BA1\u7406\u5BFE\u8C61\u306E\u5C0F\u8AAC\u3092\u66F4\u65B0\u3057\u307E\u3059\u3002\n\u66F4\u65B0\u3057\u305F\u3044\u5C0F\u8AAC\u306EN\u30B3\u30FC\u30C9\u3001URL\u3001\u30BF\u30A4\u30C8\u30EB\u3001ID\u3082\u3057\u304F\u306F\u5225\u540D\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\u5BFE\u8C61\u3092\u6307\u5B9A\u3057\u306A\u304B\u3063\u305F\u5834\u5408\u3001\u3059\u3079\u3066\u306E\u5C0F\u8AAC\u306E\u66F4\u65B0\u3092\u30C1\u30A7\u30C3\u30AF\u3057\u307E\u3059\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\u5168\u3066\u66F4\u65B0\u3059\u308B\u5834\u5408\u3001convert.no-open\u304C\u8A2D\u5B9A\u3055\u308C\u3066\u3044\u306A\u304F\u3066\u3082\u4FDD\u5B58\u30D5\u30A9\u30EB\u30C0\u306F\u958B\u304D\u307E\u305B\u3093\u3002\n\n  Example:\nnarou update               # \u5168\u3066\u66F4\u65B0\nnarou update 0 1 2 4\nnarou update n9669bk \u7570\u4E16\u754C\u8FF7\u5BAE\u3067\u5974\u96B7\u30CF\u30FC\u30EC\u30E0\u3092\nnarou update http://ncode.syosetu.com/n9669bk/\n\n  Options:\n  EOS\n  @opt.on(\"-n\", \"--no-convert\", \"\u5909\u63DB\u3092\u305B\u305A\u30A2\u30C3\u30D7\u30C7\u30FC\u30C8\u306E\u307F\u5B9F\u884C\u3059\u308B\") {\n    @options[\"no-convert\"] = true\n  }\nend\n"

Instance Method Details

#execute(argv) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
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
# File 'lib/command/update.rb', line 35

def execute(argv)
  super
  update_target_list = argv.dup
  no_open = false
  if update_target_list.empty?
    Database.instance.each_key do |id|
      update_target_list << id
    end
    no_open = true
  end
  update_target_list.each_with_index do |target, i|
    display_message = nil
    data = Downloader.get_data_by_target(target)
    if !data
      display_message = "<red>[ERROR]</red> #{target} は管理小説の中に存在しません".termcolor
    elsif Narou.novel_frozen?(target)
      if argv.length > 0
        display_message = "#{data["title"]} は凍結中です"
      else
        next
      end
    end
    Helper.print_horizontal_rule if i > 0
    if display_message
      puts display_message
      next
    end
    is_updated = Downloader.start(target)
    if is_updated
      unless @options["no-convert"]
        convert_argv = [target]
        convert_argv << "--no-open" if no_open
        Convert.execute_and_rescue_exit(convert_argv)
      end
    elsif is_updated.nil?
      puts "#{data["title"]} の更新に失敗しました"
    else
      puts "#{data["title"]} に更新はありません"
    end
  end
rescue Interrupt
  puts "アップデートを中断しました"
  exit 1
end

#oneline_helpObject



80
81
82
# File 'lib/command/update.rb', line 80

def oneline_help
  "小説を更新します"
end