class Virility::Excitation
Attributes
counts[RW]
proxy[RW]
results[RW]
strategies[RW]
url[RW]
Public Class Methods
new(url, strategies = [], proxy: {})
click to toggle source
Initialization
# File lib/virility/excitation.rb, line 10 def initialize(url, strategies = [], proxy: {}) @url = url @strategies = {} @results = {} @counts = {} @filter_strategies = strategies || [] @proxy = proxy collect_strategies filter_strategies end
Public Instance Methods
attributes()
click to toggle source
Reflection
# File lib/virility/excitation.rb, line 87 def attributes {:url => @url, :available_strategies => @strategies.keys} end
collect_strategies()
click to toggle source
Gather all of the Strategies
# File lib/virility/excitation.rb, line 69 def collect_strategies Dir["#{File.dirname(__FILE__)}/strategies/**/*.rb"].each { |klass| @strategies[get_class_string(klass).to_sym] = Virility.const_get(camelize(get_class_string(klass))).new(@url, proxy: @proxy) } end
filter_strategies()
click to toggle source
# File lib/virility/excitation.rb, line 73 def filter_strategies return if @filter_strategies.empty? @strategies.select! { |k, _v| @filter_strategies.include?(k) } end
get_response(strategy)
click to toggle source
# File lib/virility/excitation.rb, line 38 def get_response(strategy) @strategies[strategy].response if @strategies[strategy] end
get_strategy(strategy)
click to toggle source
Dynamic Methods
# File lib/virility/excitation.rb, line 95 def get_strategy strategy if strategy_exists?(strategy) @strategies[strategy.to_sym] else raise UnknownStrategy, "#{strategy} Is Not A Known Strategy" end end
method_missing(name, *args, &block)
click to toggle source
# File lib/virility/excitation.rb, line 107 def method_missing(name, *args, &block) if strategy_exists?(name) get_strategy(name) else raise UnknownStrategy, "#{name} Is Not A Known Strategy" end end
poll()
click to toggle source
Get Virility
from all of the Strategies
# File lib/virility/excitation.rb, line 25 def poll if @results.empty? @strategies.each do |name, strategy| begin @results[symbolize_for_key(strategy)] = strategy.poll rescue => e puts "[virility#poll] #{strategy.class.to_s} => #{e}" end end end @results end
strategy_exists?(strategy)
click to toggle source
# File lib/virility/excitation.rb, line 103 def strategy_exists? strategy !@strategies[strategy.to_sym].nil? end
total_virility()
click to toggle source
# File lib/virility/excitation.rb, line 60 def total_virility counts.values.inject(0) { |result, count| result + count } end
Also aliased as: total