Class: Command::Update
- Inherits:
-
CommandBase
- Object
- CommandBase
- Command::Update
- Defined in:
- lib/command/update.rb
Class Method Summary collapse
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize ⇒ Update
constructor
A new instance of Update.
Methods inherited from CommandBase
execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids
Constructor Details
#initialize ⇒ Update
Returns a new instance of Update.
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/update.rb', line 15 def initialize super("[<target> ...] [options]") @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\nExamples:\nnarou update # \u5168\u3066\u66F4\u65B0\nnarou u # \u77ED\u7E2E\u30B3\u30DE\u30F3\u30C9\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\nOptions:\n" @opt.on("-n", "--no-convert", "変換をせずアップデートのみ実行する") { ["no-convert"] = true } @opt.on("-a", "--convert-only-new-arrival", "新着のみ変換を実行する") { ["convert-only-new-arrival"] = true } end |
Class Method Details
.oneline_help ⇒ Object
11 12 13 |
# File 'lib/command/update.rb', line 11 def self.oneline_help "小説を更新します" end |
Instance Method Details
#execute(argv) ⇒ Object
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 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/command/update.rb', line 43 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 tagname_to_ids(update_target_list) update_target_list.each_with_index do |target, i| = nil data = Downloader.get_data_by_target(target) if !data = "<bold><red>[ERROR]</red></bold> #{target} は管理小説の中に存在しません".termcolor elsif Narou.novel_frozen?(target) if argv.length > 0 = "ID:#{data["id"]} #{data["title"]} は凍結中です" else next end end Helper.print_horizontal_rule if i > 0 if puts next end result = Downloader.start(target) case result.status when :ok unless ["no-convert"] or (["convert-only-new-arrival"] and not result.new_arrivals) convert_argv = [target] convert_argv << "--no-open" if no_open Convert.execute!(convert_argv) end when :failed puts "ID:#{data["id"]} #{data["title"]} の更新は失敗しました" when :canceled puts "ID:#{data["id"]} #{data["title"]} の更新はキャンセルされました" when :none puts "#{data["title"]} に更新はありません" end end rescue Interrupt puts "アップデートを中断しました" exit 1 end |