Class: Command::Browser
- Inherits:
-
CommandBase
- Object
- CommandBase
- Command::Browser
- Defined in:
- lib/command/browser.rb
Instance Attribute Summary
Attributes inherited from CommandBase
Class Method Summary collapse
Instance Method Summary collapse
- #execute(argv) ⇒ Object
-
#initialize ⇒ Browser
constructor
A new instance of Browser.
Methods inherited from CommandBase
#disable_logging, #display_help!, execute!, #execute!, #force_change_settings_function, help, #hook_call, #load_local_settings, #tagname_to_ids
Constructor Details
#initialize ⇒ Browser
Returns a new instance of Browser.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/command/browser.rb', line 15 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 |
Class Method Details
.oneline_help ⇒ Object
11 12 13 |
# File 'lib/command/browser.rb', line 11 def self.oneline_help "小説の掲載ページをブラウザで開きます" end |
Instance Method Details
#execute(argv) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/command/browser.rb', line 34 def execute(argv) super display_help! if argv.empty? 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.unsafe_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 |