Class: Retort::Rtorrent

Inherits:
Object
  • Object
show all
Defined in:
lib/retort/rtorrent.rb

Direct Known Subclasses

File, Torrent

Constant Summary collapse

TYPES =
{
  time: 'to_time',
  date: 'to_date',
  size: 'to_xb'
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.attr_mappingsObject

Returns the value of attribute attr_mappings.



11
12
13
# File 'lib/retort/rtorrent.rb', line 11

def attr_mappings
  @attr_mappings
end

.attributesObject

Returns the value of attribute attributes.



11
12
13
# File 'lib/retort/rtorrent.rb', line 11

def attributes
  @attributes
end

.attributes_rawObject

Returns the value of attribute attributes_raw.



11
12
13
# File 'lib/retort/rtorrent.rb', line 11

def attributes_raw
  @attributes_raw
end

.prefixObject

Returns the value of attribute prefix.



11
12
13
# File 'lib/retort/rtorrent.rb', line 11

def prefix
  @prefix
end

Class Method Details

.attribute(property, options = {}, &block) ⇒ Object Also known as: method_missing



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/retort/rtorrent.rb', line 21

def attribute(property, options = {}, &block)
  type = options[:type]
  method_name = options[:name] || property
  method_name = "#{self.prefix}.#{method_name}" unless self.prefix.empty?
  self.attributes_raw[property] = method_name

  if TYPES.member? type
    #Syntax is 'to_*=$.....'. Example : 'to_date=$d.get_creation_date'.
    self.attributes[property] = "#{TYPES[type]}=$#{method_name}"
    property = "#{property}_raw"
  end
  self.attributes[property] = method_name
end

.setup(prefix = "", &block) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/retort/rtorrent.rb', line 13

def setup(prefix="", &block)
  self.prefix = prefix
  self.attributes = {}
  self.attributes_raw = {}

  instance_eval(&block)
end