Sha256: 4d10bc5edf90a4895ea5640f25b86c662f0ab47d87db4700cb299fbc1802f0be

Contents?: true

Size: 1.48 KB

Versions: 62

Compression:

Stored size: 1.48 KB

Contents

# -*- coding: utf-8 -*-
#
# Copyright 2013 whiteleaf. All rights reserved.
#

require_relative "../inventory"

module Command
  class Browser < CommandBase
    def self.oneline_help
      "小説の掲載ページをブラウザで開きます"
    end

    def initialize
      super("<target> [<target2> ...] [options]")
      @opt.separator <<-EOS

  ・指定した小説の掲載ページをブラウザで開きます。

  Examples:
    narou browser n9669bk
    narou browser musyoku -v
    narou b 0

  Options:
      EOS

      @opt.on("-v", "--vote", "小説の投票・感想を投稿するページを表示する(なろうのみ)") {
        @options["vote"] = true
      }
    end

    def execute(argv)
      super
      if argv.empty?
        puts @opt.help
        return
      end
      tagname_to_ids(argv)
      argv.each do |target|
        data = Downloader.get_data_by_target(target)
        unless data
          error "#{target} は存在しません"
          next
        end
        toc_url = data["toc_url"]
        if @options["vote"]
          # TODO: 最新話の場所をAPIで取得する
          data_dir = Downloader.get_novel_data_dir_by_target(data["id"])
          latest_index = YAML.load_file(File.join(data_dir, Downloader::TOC_FILE_NAME))["subtitles"].last["index"]
          open_url = "#{toc_url + latest_index}/#my_novelpoint"
        else
          open_url = toc_url
        end
        Helper.open_browser(open_url)
        puts open_url
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
narou-3.2.5.1 lib/command/browser.rb
narou-3.2.5 lib/command/browser.rb
narou-3.2.4 lib/command/browser.rb
narou-3.2.3 lib/command/browser.rb
narou-3.2.2 lib/command/browser.rb
narou-3.2.1 lib/command/browser.rb
narou-3.2.0.1 lib/command/browser.rb
narou-3.2.0 lib/command/browser.rb
narou-3.1.11 lib/command/browser.rb
narou-3.1.10 lib/command/browser.rb
narou-3.1.9 lib/command/browser.rb
narou-3.1.8 lib/command/browser.rb
narou-3.1.7 lib/command/browser.rb
narou-3.1.6 lib/command/browser.rb
narou-3.1.5 lib/command/browser.rb
narou-3.1.4 lib/command/browser.rb
narou-3.1.3 lib/command/browser.rb
narou-3.1.2 lib/command/browser.rb
narou-3.1.1 lib/command/browser.rb
narou-3.0.5.1 lib/command/browser.rb