Class: Rootor
- Inherits:
-
Object
- Object
- Rootor
- Defined in:
- lib/rootor.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#torrents ⇒ Object
Returns the value of attribute torrents.
Instance Method Summary collapse
- #find(str) ⇒ Object
-
#initialize(xmlrpc_url) ⇒ Rootor
constructor
A new instance of Rootor.
- #json_torrents ⇒ Object
- #load_from_file(path) ⇒ Object
- #load_from_raw(data) ⇒ Object
- #refresh! ⇒ Object
- #remove(hash) ⇒ Object
- #serialized_torrents ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/rootor.rb', line 9 def client @client end |
#torrents ⇒ Object
Returns the value of attribute torrents.
9 10 11 |
# File 'lib/rootor.rb', line 9 def torrents @torrents end |
Instance Method Details
#find(str) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/rootor.rb', line 28 def find(str) return [] if str.empty? || !str.instance_of?(String) @torrents.map do |t| t if t.serialize.values.any? { |tt| tt.downcase.include? str.downcase } rescue nil end.compact end |
#json_torrents ⇒ Object
24 25 26 |
# File 'lib/rootor.rb', line 24 def json_torrents serialized_torrents.to_json end |
#load_from_file(path) ⇒ Object
43 44 45 |
# File 'lib/rootor.rb', line 43 def load_from_file(path) load_from_raw(File.read(path)) end |
#load_from_raw(data) ⇒ Object
35 36 37 |
# File 'lib/rootor.rb', line 35 def load_from_raw(data) @client.load_start(XMLRPC::Base64.new(data)) end |
#refresh! ⇒ Object
16 17 18 |
# File 'lib/rootor.rb', line 16 def refresh! @torrents = @client.fetch end |
#remove(hash) ⇒ Object
39 40 41 |
# File 'lib/rootor.rb', line 39 def remove(hash) @client.erase(hash) end |
#serialized_torrents ⇒ Object
20 21 22 |
# File 'lib/rootor.rb', line 20 def serialized_torrents @torrents.map(&:serialize) end |