Class: LjoyceCustomerScoring::Analysis
- Inherits:
-
Object
- Object
- LjoyceCustomerScoring::Analysis
- Defined in:
- lib/ljoyce_customer_scoring.rb
Instance Attribute Summary collapse
-
#propensity ⇒ Object
readonly
Returns the value of attribute propensity.
-
#ranking ⇒ Object
readonly
Returns the value of attribute ranking.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input) ⇒ Analysis
constructor
Creates an instance of the Analysis class, which assigns values to instance variables @propensity and @ranking based on the input hash.
Constructor Details
#initialize(input) ⇒ Analysis
Creates an instance of the Analysis class, which assigns values to instance variables @propensity and @ranking based on the input hash
8 9 10 11 |
# File 'lib/ljoyce_customer_scoring.rb', line 8 def initialize(input) @propensity = input["propensity"] @ranking = input["ranking"] end |
Instance Attribute Details
#propensity ⇒ Object (readonly)
Returns the value of attribute propensity.
6 7 8 |
# File 'lib/ljoyce_customer_scoring.rb', line 6 def propensity @propensity end |
#ranking ⇒ Object (readonly)
Returns the value of attribute ranking.
6 7 8 |
# File 'lib/ljoyce_customer_scoring.rb', line 6 def ranking @ranking end |
Class Method Details
.request(request_parameters) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ljoyce_customer_scoring.rb', line 13 def self.request(request_parameters) # If request_parameters is meets the following argument requirements if request_parameters.class == Hash && request_parameters[:income] && request_parameters[:zipcode] && request_parameters[:age] && request_parameters[:income] > 0 && request_parameters[:zipcode].to_s.length == 5 && request_parameters[:age] > 0 # Using a mock api endpoint mock_api = "http://www.mocky.io/v2/58b906ee0f00006706f09b9b" data = Unirest.get( "#{mock_api}? income=#{request_parameters[:income]}& zipcode=#{request_parameters[:zipcode]}& age=#{request_parameters[:age]}" ).body # Use this hash to instantiate Analysis – Analysis.initialize(request_result), which returns instance variables @propensity and @ranking request_result = { "propensity" => data[0]["propensity"], "ranking" => data[0]["ranking"] } analysis = Analysis.new(request_result) return analysis else # If request_parameter is invalid = "Invalid request: must include valid request parameters for income, zipcode, age." return end end |