Class: Command::Download
- Inherits:
-
CommandBase
- Object
- CommandBase
- Command::Download
- Defined in:
- lib/command/download.rb
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize ⇒ Download
constructor
A new instance of Download.
- #oneline_help ⇒ Object
Methods inherited from CommandBase
Constructor Details
#initialize ⇒ Download
Returns a new instance of Download.
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 |
# File 'lib/command/download.rb', line 11 def initialize super("<target> [<target2> ...] [options]") @opt.separator <<-EOS ・ダウンロードしたい小説のNコードもしくはURLを指定して下さい。 ・一度に複数の小説を指定する場合は空白で区切って下さい。 ・ダウンロード終了後に変換処理を行います。ダウンロードのみする場合は-nオプションを指定して下さい。 ・すでにダウンロード済みの小説の場合は何もしません。 Example: narou download n9669bk narou download http://ncode.syosetu.com/n9669bk/ narou download n9669bk http://ncode.syosetu.com/n4259s/ narou download 0 1 -f narou download n9669bk -n Options: EOS @opt.on("-f", "--force", "全話を再ダウンロードする。中身が同じなら上書きはしない") { @options["force"] = true } @opt.on("-n", "--no-convert", "変換をせずダウンロードのみ実行する") { @options["no-convert"] = true } end |
Instance Method Details
#execute(argv) ⇒ Object
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 |
# File 'lib/command/download.rb', line 37 def execute(argv) super if argv.empty? puts @opt.help return end argv.each.with_index(1) do |target, i| download_target ||= target Helper.print_horizontal_rule if i > 1 data = Downloader.get_data_by_target(download_target) if Narou.novel_frozen?(download_target) puts "#{data["title"]} は凍結中です\nダウンロードを中止しました" next end if !@options["force"] && data if Downloader.get_novel_data_dir_by_target(download_target) puts "#{download_target} はダウンロード済みです。" puts "ID: #{data["id"]}" puts "title: #{data["title"]}" else if Helper.confirm("再ダウンロードしますか") download_target = data["toc_url"] redo end end next end unless Downloader.start(download_target, @options["force"]) next end unless @options["no-convert"] Convert.execute_and_rescue_exit([download_target]) end end end |
#oneline_help ⇒ Object
73 74 75 |
# File 'lib/command/download.rb', line 73 def oneline_help "指定した小説をダウンロードします" end |