lib/zold/remotes.rb in zold-0.2 vs lib/zold/remotes.rb in zold-0.3

- old
+ new

@@ -58,26 +58,32 @@ def exists?(host, port = Remotes::PORT) !load.find { |r| r[:host] == host && r[:port] == port }.nil? end def add(host, port = Remotes::PORT) + raise 'Port has to be of type Integer' unless port.is_a?(Integer) + raise 'Port can\'t be negative' if port < 0 + raise 'Port can\'t be over 65536' if port > 0xffff list = load list << { host: host, port: port, score: 0 } list.uniq! { |r| "#{r[:host]}:#{r[:port]}" } save(list) end def remove(host, port = Remotes::PORT) + raise 'Port has to be of type Integer' unless port.is_a?(Integer) list = load list.reject! { |r| r[:host] == host && r[:port] == port } save(list) end def score(host, port = Remotes::PORT) + raise 'Port has to be of type Integer' unless port.is_a?(Integer) load.find { |r| r[:host] == host && r[:port] == port }[:score] end def rescore(host, port, score) + raise 'Port has to be of type Integer' unless port.is_a?(Integer) list = load list.find do |r| r[:host] == host && r[:port] == port end[:score] = score save(list)