Sha256: 1a8eda1a14b00a35e03785ccdc41c16bb2e10a5aa737f9962e5b3547f7ae9392

Contents?: true

Size: 1.93 KB

Versions: 25

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

#
# Copyright 2013 whiteleaf. All rights reserved.
#

require_relative "../database"
require_relative "../downloader"
require_relative "../inventory"

module Command
  class Freeze < CommandBase
    def self.oneline_help
      "小説の凍結設定を行います"
    end

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

  ・指定した小説を凍結し、変更不可属性を付与します。
  ・凍結することでダウンロード、アップデート及び削除が出来なくなります。
  ・凍結済みの小説を指定した場合、凍結が解除されます。

  Examples:
    narou freeze --list
    narou freeze n9669bk
    narou freeze 0 1 musyoku

  Options:
      EOS
      @opt.on("-l", "--list", "凍結中小説の一覧を表示") {
        output_freeze_list
        exit 0
      }
      @opt.on("--on", "現在の状態にかかわらず凍結する") {
        @options["on"] = true
      }
      @opt.on("--off", "現在の状態にかかわらず解除する") {
        @options["off"] = true
      }
    end

    def output_freeze_list
      List.execute!("--filter", "frozen")
    end

    def execute(argv)
      super
      display_help! if argv.empty?
      tagname_to_ids(argv)
      frozen_list = Inventory.load("freeze")
      argv.each do |target|
        data = Downloader.get_data_by_target(target)
        unless data
          puts "#{target} は存在しません"
          next
        end
        id, title = data["id"], data["title"]
        flag = !frozen_list.include?(id)
        flag = true if @options["on"]
        flag = false if @options["off"]
        if flag
          frozen_list[id] = true
          puts "#{title} を凍結しました"
        else
          frozen_list.delete(id)
          puts "#{title} の凍結を解除しました"
          next
        end
      end
      frozen_list.save
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
narou-3.9.1 lib/command/freeze.rb
narou-3.9.0 lib/command/freeze.rb
narou-3.8.2 lib/command/freeze.rb
narou-3.8.1 lib/command/freeze.rb
narou-3.8.0 lib/command/freeze.rb
narou-3.7.2 lib/command/freeze.rb
narou-3.7.1 lib/command/freeze.rb
narou-3.7.0 lib/command/freeze.rb
narou-3.6.0 lib/command/freeze.rb
narou-3.5.1 lib/command/freeze.rb
narou-3.5.0.1 lib/command/freeze.rb
narou-3.5.0 lib/command/freeze.rb
narou-3.4.8 lib/command/freeze.rb
narou-3.4.7.1 lib/command/freeze.rb
narou-3.4.7 lib/command/freeze.rb
narou-3.4.6.1 lib/command/freeze.rb
narou-3.4.6 lib/command/freeze.rb
narou-3.4.5 lib/command/freeze.rb
narou-3.4.3 lib/command/freeze.rb
narou-3.4.2 lib/command/freeze.rb