Class: Transmission::Arguments

Inherits:
Object
  • Object
show all
Extended by:
Utils
Defined in:
lib/transmission/arguments.rb,
lib/transmission/arguments/session_set.rb,
lib/transmission/arguments/torrent_add.rb,
lib/transmission/arguments/torrent_set.rb,
lib/transmission/arguments/location_set.rb

Direct Known Subclasses

LocationSet, SessionSet, TorrentAdd, TorrentSet

Defined Under Namespace

Classes: InvalidArgument, LocationSet, SessionSet, TorrentAdd, TorrentSet

Constant Summary collapse

ATTRIBUTES =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

is_valid_key?, option_key, option_keys

Constructor Details

#initialize(arguments = nil) ⇒ Arguments

Returns a new instance of Arguments.



15
16
17
18
19
20
21
22
23
24
# File 'lib/transmission/arguments.rb', line 15

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

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



11
12
13
# File 'lib/transmission/arguments.rb', line 11

def arguments
  @arguments
end

Class Method Details

.filter(arguments) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/transmission/arguments.rb', line 41

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

.is_valid?(key) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/transmission/arguments.rb', line 33

def is_valid?(key)
  is_valid_key? key, self::ATTRIBUTES
end

.real_key(key) ⇒ Object



37
38
39
# File 'lib/transmission/arguments.rb', line 37

def real_key(key)
  option_key key, self::ATTRIBUTES
end

Instance Method Details

#to_argumentsObject



26
27
28
# File 'lib/transmission/arguments.rb', line 26

def to_arguments
  @arguments
end