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.
-
#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.
- #get_response(strategy) ⇒ Object
-
#get_strategy(strategy) ⇒ Object
Dynamic Methods.
-
#initialize(url) ⇒ 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) ⇒ Excitation
Initialization
11 12 13 14 15 16 17 |
# File 'lib/virility/excitation.rb', line 11 def initialize url @url = url @strategies = {} @results = {} @counts = {} collect_strategies end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/virility/excitation.rb', line 95 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
44 45 46 |
# File 'lib/virility/excitation.rb', line 44 def counts @counts 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
75 76 77 |
# File 'lib/virility/excitation.rb', line 75 def attributes {:url => @url, :available_strategies => @strategies.keys} end |
#collect_strategies ⇒ Object
Gather all of the Strategies
67 68 69 |
# File 'lib/virility/excitation.rb', line 67 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) } end |
#get_response(strategy) ⇒ Object
36 37 38 |
# File 'lib/virility/excitation.rb', line 36 def get_response(strategy) @strategies[strategy].response if @strategies[strategy] end |
#get_strategy(strategy) ⇒ Object
Dynamic Methods
83 84 85 86 87 88 89 |
# File 'lib/virility/excitation.rb', line 83 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
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/virility/excitation.rb', line 23 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
91 92 93 |
# File 'lib/virility/excitation.rb', line 91 def strategy_exists? strategy !@strategies[strategy.to_sym].nil? end |
#total_virility ⇒ Object Also known as: total
58 59 60 |
# File 'lib/virility/excitation.rb', line 58 def total_virility counts.values.inject(0) { |result, count| result + count } end |