retort 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ class Float
10
10
  end
11
11
 
12
12
  def percent
13
- "#{sprintf('%.2f', percent_raw)}"
13
+ "#{percent_raw}%"
14
14
  end
15
15
  end
16
16
 
@@ -0,0 +1,39 @@
1
+ class Retort::Rtorrent
2
+
3
+ TYPES = {
4
+ time: 'to_time',
5
+ date: 'to_date',
6
+ size: 'to_xb'
7
+ }
8
+
9
+ class << self
10
+
11
+ attr_accessor :prefix, :attr_mappings, :attributes, :attributes_raw
12
+
13
+ def setup(prefix="", &block)
14
+ self.prefix = prefix
15
+ self.attributes = {}
16
+ self.attributes_raw = {}
17
+
18
+ instance_eval(&block)
19
+ end
20
+
21
+ def attribute(property, options = {}, &block)
22
+ type = options[:type]
23
+ method_name = options[:name] || property
24
+ method_name = "#{self.prefix}.#{method_name}" unless self.prefix.empty?
25
+ self.attributes_raw[property] = method_name
26
+
27
+ if TYPES.member? type
28
+ #Syntax is 'to_*=$.....'. Example : 'to_date=$d.get_creation_date'.
29
+ self.attributes[property] = "#{TYPES[type]}=$#{method_name}"
30
+ property = "#{property}_raw"
31
+ end
32
+ self.attributes[property] = method_name
33
+ end
34
+
35
+ alias method_missing attribute
36
+ end
37
+
38
+ end
39
+
@@ -4,35 +4,34 @@ module Retort
4
4
 
5
5
  class Torrent < Rtorrent
6
6
 
7
+ setup :d do
8
+ info_hash name: 'hash'
9
+ name
10
+ connection_current
11
+ size name: 'size_bytes', type: :size
12
+ completed name: 'completed_bytes', type: :size
13
+ creation_date name: 'creation_date', type: :date
14
+ downloaded name: 'bytes_done', type: :size
15
+ up_rate name: 'up.rate', type: :size
16
+ down_rate name: 'down.rate', type: :size
17
+ message name: 'get_message'
18
+ seeders name: 'peers_complete'
19
+ leechers name: 'peers_connected'
20
+ state
21
+ complete
22
+ is_active
23
+ is_hash_checked
24
+ is_hash_checking
25
+ is_multi_file
26
+ is_open
27
+ end
28
+
7
29
  class << self
8
- def attr_mappings
9
- @@mappings ||= build(:d) do
10
- info_hash name: 'hash'
11
- name
12
- connection_current
13
- size name: 'size_bytes', type: :size
14
- completed name: 'completed_bytes', type: :size
15
- creation_date name: 'creation_date', type: :date
16
- downloaded name: 'bytes_done', type: :size
17
- up_rate name: 'up.rate', type: :size
18
- down_rate name: 'down.rate', type: :size
19
- message name: 'get_message'
20
- seeders name: 'peers_complete'
21
- leechers name: 'peers_connected'
22
- state
23
- complete
24
- is_active
25
- is_hash_checked
26
- is_hash_checking
27
- is_multi_file
28
- is_open
29
- end
30
- end
31
30
 
32
31
  def all(view="main")
33
- methods = attr_mappings.map {|key,value| "#{value}="}
32
+ methods = attributes.map {|key,value| "#{value}="}
34
33
  Service.call("d.multicall", view, *methods).map do |r|
35
- attributes = Hash[attr_mappings.keys.zip(r)]
34
+ attributes = Hash[self.attributes.keys.zip(r)]
36
35
  Torrent.new attributes
37
36
  end
38
37
  end
@@ -50,7 +49,7 @@ module Retort
50
49
  end
51
50
  end
52
51
 
53
- attr_accessor *(attr_mappings.keys)
52
+ attr_accessor *(attributes.keys)
54
53
 
55
54
  def initialize(attributes)
56
55
 
@@ -66,6 +65,10 @@ module Retort
66
65
 
67
66
  end
68
67
 
68
+ def completed_ratio
69
+ self.completed_raw/(self.size_raw.to_f)
70
+ end
71
+
69
72
  def status
70
73
  return "complete" if @complete.truth
71
74
  end
@@ -1,3 +1,3 @@
1
1
  module Retort
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/retort.rb CHANGED
@@ -2,7 +2,7 @@ require 'retort/version'
2
2
  require 'retort/core_ext'
3
3
  require 'retort/xmlrpc_client'
4
4
  require 'retort/service'
5
- require 'retort/conversion'
5
+ require 'retort/rtorrent'
6
6
  require 'retort/torrent'
7
7
 
8
8
  module Retort
@@ -2,9 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Retort::Torrent do
4
4
  it "has all methods listed" do
5
- all_methods = Retort::Service.call "system.listMethods"
6
- torrent_methods = Retort::Torrent.attr_mappings.values.reject {|x| x =~ /\$/}
7
- x = torrent_methods.reject {|m| all_methods.include?(m)}
8
- x.size.should == 0
5
+ all_methods = Retort::Service.call("system.listMethods").to_set
6
+ torrent_methods = Retort::Torrent.attributes_raw.values.to_set
7
+ torrent_methods.subset?(all_methods).should == true
9
8
  end
10
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retort
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-11 00:00:00.000000000Z
12
+ date: 2011-09-16 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &11591600 !ruby/object:Gem::Requirement
16
+ requirement: &16031180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11591600
24
+ version_requirements: *16031180
25
25
  description: An rTorrent xmlrpc wrapper written in ruby
26
26
  email:
27
27
  - marcel.morgan@gmail.com
@@ -38,8 +38,8 @@ files:
38
38
  - Rakefile
39
39
  - autotest/discover.rb
40
40
  - lib/retort.rb
41
- - lib/retort/conversion.rb
42
41
  - lib/retort/core_ext.rb
42
+ - lib/retort/rtorrent.rb
43
43
  - lib/retort/service.rb
44
44
  - lib/retort/torrent.rb
45
45
  - lib/retort/version.rb
@@ -1,40 +0,0 @@
1
- class Retort::Rtorrent
2
-
3
- TYPES = {
4
- time: 'to_time',
5
- date: 'to_date',
6
- size: 'to_xb'
7
- }
8
-
9
- attr_accessor :attributes, :attributes_raw
10
-
11
- def initialize(prefix)
12
- @attributes = {}
13
- @attributes_raw = {}
14
- @prefix = prefix
15
- end
16
-
17
- def attribute(property, options = {}, &block)
18
- type = options[:type]
19
- method_name = options[:name] || property
20
- method_name = "#{@prefix}.#{method_name}" unless @prefix.empty?
21
- @attributes_raw[property] = method_name
22
-
23
- if TYPES.member? type
24
- #Syntax is 'to_*=$.....'. Example : 'to_date=$d.get_creation_date'.
25
- @attributes[property] = "#{TYPES[type]}=$#{method_name}"
26
- property = "#{property}_raw"
27
- end
28
- @attributes[property] = method_name
29
- end
30
-
31
- alias method_missing attribute
32
-
33
- def self.build(prefix="", &block)
34
- c = new(prefix)
35
- c.instance_eval(&block)
36
- c.attributes
37
- end
38
-
39
- end
40
-