Class: Virility::Strategy
- Inherits:
-
Object
- Object
- Virility::Strategy
- Includes:
- HTTParty, Supporter
- Defined in:
- lib/virility/strategy.rb
Instance Attribute Summary collapse
-
#http_proxyaddr ⇒ Object
Returns the value of attribute http_proxyaddr.
-
#http_proxyport ⇒ Object
Returns the value of attribute http_proxyport.
-
#original_url ⇒ Object
Returns the value of attribute original_url.
-
#response ⇒ Object
Returns the value of attribute response.
-
#results ⇒ Object
Returns the value of attribute results.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#call_strategy ⇒ Object
Call Strategy.
-
#census ⇒ Object
Abstract Methods - Delete eventually.
-
#collect_results ⇒ Object
Results.
- #count ⇒ Object
-
#get_result(key) ⇒ Object
Dynamic Methods.
-
#initialize(url, proxy: {}) ⇒ Strategy
constructor
A new instance of Strategy.
- #method_missing(name, *args, &block) ⇒ Object
-
#poll ⇒ Object
Poll.
- #result_exists?(key) ⇒ Boolean
-
#valid_response_test ⇒ Object
Parsed Response Test - Overwrite if needed.
Methods included from Supporter
#camelize, #encode, #escaped_url, #get_class_string, #symbolize_for_key, #underscore
Constructor Details
#initialize(url, proxy: {}) ⇒ Strategy
Returns a new instance of Strategy.
8 9 10 11 12 13 14 |
# File 'lib/virility/strategy.rb', line 8 def initialize(url, proxy: {}) @original_url = url @url = encode(url) @results = {} @http_proxyaddr = proxy.dig(:http_proxyaddr) @http_proxyport = proxy.dig(:http_proxyport) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/virility/strategy.rb', line 84 def method_missing(name, *args, &block) if result_exists?(name) get_result(name) else 0 end end |
Instance Attribute Details
#http_proxyaddr ⇒ Object
Returns the value of attribute http_proxyaddr.
6 7 8 |
# File 'lib/virility/strategy.rb', line 6 def http_proxyaddr @http_proxyaddr end |
#http_proxyport ⇒ Object
Returns the value of attribute http_proxyport.
6 7 8 |
# File 'lib/virility/strategy.rb', line 6 def http_proxyport @http_proxyport end |
#original_url ⇒ Object
Returns the value of attribute original_url.
6 7 8 |
# File 'lib/virility/strategy.rb', line 6 def original_url @original_url end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/virility/strategy.rb', line 6 def response @response end |
#results ⇒ Object
Returns the value of attribute results.
6 7 8 |
# File 'lib/virility/strategy.rb', line 6 def results @results end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/virility/strategy.rb', line 6 def url @url end |
Instance Method Details
#call_strategy ⇒ Object
Call Strategy
41 42 43 |
# File 'lib/virility/strategy.rb', line 41 def call_strategy @response = census end |
#census ⇒ Object
Abstract Methods - Delete eventually
20 21 22 |
# File 'lib/virility/strategy.rb', line 20 def census raise "Abstract Method census called on #{self.class} - Please define this method" end |
#collect_results ⇒ Object
Results
49 50 51 52 53 54 55 |
# File 'lib/virility/strategy.rb', line 49 def collect_results if respond_to?(:outcome) @results = valid_response_test ? outcome : {} else @results = valid_response_test ? @response.parsed_response : {} end end |
#count ⇒ Object
24 25 26 |
# File 'lib/virility/strategy.rb', line 24 def count raise "Abstract Method count called on #{self.class} - Please define this method" end |
#get_result(key) ⇒ Object
Dynamic Methods
72 73 74 75 76 77 78 |
# File 'lib/virility/strategy.rb', line 72 def get_result key if result_exists?(key) results[key.to_s] else 0 end end |
#poll ⇒ Object
Poll
32 33 34 35 |
# File 'lib/virility/strategy.rb', line 32 def poll call_strategy collect_results end |
#result_exists?(key) ⇒ Boolean
80 81 82 |
# File 'lib/virility/strategy.rb', line 80 def result_exists? key !results[key.to_s].nil? end |
#valid_response_test ⇒ Object
Parsed Response Test - Overwrite if needed
96 97 98 |
# File 'lib/virility/strategy.rb', line 96 def valid_response_test @response.respond_to?(:parsed_response) and @response.parsed_response.is_a?(Hash) end |