module Ocawari
Constants
- VERSION
- WINDOWS_CHROME_USER_AGENT
- WINDOWS_EDGE_USER_AGENT
Public Class Methods
parse(args)
click to toggle source
# File lib/ocawari.rb, line 16 def self.parse(args) case args when Array return [] if args.empty? work_queue = Queue.new mutex = Mutex.new collected_images = [] strategies = args.map do |url| uri = prepare_uri(url) strategy = StrategyDelegator.identify(uri.to_s) [ strategy, uri ] end strategies.each { |taskset| work_queue << taskset } (0..4).map do |_| Thread.new do begin while taskset = work_queue.pop(true) strategy, uri = taskset task = strategy.new(uri) images = task.execute mutex.lock collected_images += images mutex.unlock end rescue ThreadError end end end.map(&:join) collected_images.compact when String return [] if args.empty? uri = prepare_uri(args) strategy = StrategyDelegator.identify(uri.to_s) strategy.new(uri).execute else [] end end
Private Class Methods
prepare_uri(url)
click to toggle source
# File lib/ocawari.rb, line 64 def self.prepare_uri(url) u = Addressable::URI.parse(url) if u.scheme.nil? Addressable::URI.parse("http://#{u.to_s}").normalize else u.normalize end end