Class: Rootor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xmlrpc_url) ⇒ Rootor

Returns a new instance of Rootor.



11
12
13
14
# File 'lib/rootor.rb', line 11

def initialize(xmlrpc_url)
  @client = Client.new2(xmlrpc_url)
  @torrents = refresh!
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



9
10
11
# File 'lib/rootor.rb', line 9

def client
  @client
end

#torrentsObject

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_torrentsObject



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_torrentsObject



20
21
22
# File 'lib/rootor.rb', line 20

def serialized_torrents
  @torrents.map(&:serialize)
end