class TorrentSearch::Controllers::Download
Constants
- DEFAULT_DIR
Public Class Methods
new(search_result, view = Views::Download.new)
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 6 def initialize(search_result, view = Views::Download.new) @search_result = search_result @view = view end
Public Instance Methods
download()
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 11 def download perform_download choose_torrent!, choose_path! end
Private Instance Methods
choose_path!()
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 37 def choose_path! path = @view.directory? DEFAULT_DIR path.empty? ? DEFAULT_DIR : path end
choose_torrent!()
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 29 def choose_torrent! while index = @view.torrent?(search_result_range.max) return @search_result[index.to_i] if valid_choice?(index) @view.invalid_option! end end
is_in_search_result?(index)
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 46 def is_in_search_result?(index) search_result_range.member?(index.to_i) end
open(filename)
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 25 def open(filename) `open #{filename}` end
perform_download(torrent, path)
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 16 def perform_download(torrent, path) @view.downloading! torrent download = Services::Download.new(path, torrent) download.perform @view if download.success? && OS.os_x? && @view.open? open download.filename end end
search_result_range()
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 50 def search_result_range @range ||= Range.new(0, @search_result.length, true) end
valid_choice?(index)
click to toggle source
# File lib/torrent_search/controllers/download.rb, line 42 def valid_choice?(index) index.match(/\A\d+\z/) && is_in_search_result?(index) end