Sha256: 18aff7f63295e6f11711d19b48aa53cfbacd8df46a6f6f6df5398eb30c7cc933
Contents?: true
Size: 1.31 KB
Versions: 4
Compression:
Stored size: 1.31 KB
Contents
require File.join(File.dirname(__FILE__), 'arguments', 'torrent_add') require File.join(File.dirname(__FILE__), 'arguments', 'torrent_set') require File.join(File.dirname(__FILE__), 'arguments', 'session_set') require File.join(File.dirname(__FILE__), 'utils') module Transmission class Arguments class InvalidArgument < StandardError; end attr_accessor :arguments ATTRIBUTES = [] def initialize(arguments = nil) @arguments = arguments.inject({}) do |attributes, (key, value)| key = key.to_s found = self.class::ATTRIBUTES.select { |attr| attr[:field] == key } raise Transmission::Arguments::InvalidArgument, key if found.empty? attributes[key] = value attributes end if arguments @arguments = self.class::ATTRIBUTES if arguments.nil? end def to_arguments @arguments end class << self include Transmission::Utils def is_valid?(key) is_valid_key? key, self::ATTRIBUTES end def real_key(key) option_key key, self::ATTRIBUTES end def filter(arguments) arguments.inject({}) do |hash, (key, value)| found = self::ATTRIBUTES.select { |attr| attr[:field] == key.to_s } hash[key] = value unless found.empty? hash end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems