Class: Virility::Excitation
- Inherits:
-
Object
- Object
- Virility::Excitation
- Includes:
- Supporter
- Defined in:
- lib/virility/excitation.rb
Instance Attribute Summary collapse
-
#counts ⇒ Object
Return Collected Counts as a Hash.
-
#proxy ⇒ Object
Returns the value of attribute proxy.
-
#results ⇒ Object
Returns the value of attribute results.
-
#strategies ⇒ Object
Returns the value of attribute strategies.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#attributes ⇒ Object
Reflection.
-
#collect_strategies ⇒ Object
Gather all of the Strategies.
- #filter_strategies ⇒ Object
- #get_response(strategy) ⇒ Object
-
#get_strategy(strategy) ⇒ Object
Dynamic Methods.
-
#initialize(url, strategies = [], proxy: {}) ⇒ Excitation
constructor
Initialization.
- #method_missing(name, *args, &block) ⇒ Object
-
#poll ⇒ Object
Get Virility from all of the Strategies.
- #strategy_exists?(strategy) ⇒ Boolean
- #total_virility ⇒ Object (also: #total)
Methods included from Supporter
#camelize, #encode, #escaped_url, #get_class_string, #symbolize_for_key, #underscore
Constructor Details
#initialize(url, strategies = [], proxy: {}) ⇒ Excitation
Initialization
10 11 12 13 14 15 16 17 18 19 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
107 108 109 110 111 112 113 |
# 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 |
Instance Attribute Details
#counts ⇒ Object
Return Collected Counts as a Hash
46 47 48 |
# File 'lib/virility/excitation.rb', line 46 def counts @counts end |
#proxy ⇒ Object
Returns the value of attribute proxy.
5 6 7 |
# File 'lib/virility/excitation.rb', line 5 def proxy @proxy end |
#results ⇒ Object
Returns the value of attribute results.
5 6 7 |
# File 'lib/virility/excitation.rb', line 5 def results @results end |
#strategies ⇒ Object
Returns the value of attribute strategies.
5 6 7 |
# File 'lib/virility/excitation.rb', line 5 def strategies @strategies end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/virility/excitation.rb', line 5 def url @url end |
Instance Method Details
#attributes ⇒ Object
Reflection
87 88 89 |
# File 'lib/virility/excitation.rb', line 87 def attributes {:url => @url, :available_strategies => @strategies.keys} end |
#collect_strategies ⇒ Object
Gather all of the Strategies
69 70 71 |
# 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 ⇒ Object
73 74 75 76 |
# 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) ⇒ Object
38 39 40 |
# File 'lib/virility/excitation.rb', line 38 def get_response(strategy) @strategies[strategy].response if @strategies[strategy] end |
#get_strategy(strategy) ⇒ Object
Dynamic Methods
95 96 97 98 99 100 101 |
# 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 |
#poll ⇒ Object
Get Virility from all of the Strategies
25 26 27 28 29 30 31 32 33 34 35 36 |
# 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) ⇒ Boolean
103 104 105 |
# File 'lib/virility/excitation.rb', line 103 def strategy_exists? strategy !@strategies[strategy.to_sym].nil? end |
#total_virility ⇒ Object Also known as: total
60 61 62 |
# File 'lib/virility/excitation.rb', line 60 def total_virility counts.values.inject(0) { |result, count| result + count } end |