Class: GovukAbTesting::RequestedVariant
- Inherits:
-
Object
- Object
- GovukAbTesting::RequestedVariant
- Defined in:
- lib/govuk_ab_testing/requested_variant.rb
Instance Attribute Summary collapse
-
#ab_test ⇒ Object
readonly
Returns the value of attribute ab_test.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
-
#analytics_meta_tag ⇒ String
HTML meta tag used to track the results of your experiment.
-
#configure_response(response) ⇒ Object
Configure the response.
-
#initialize(ab_test, request) ⇒ RequestedVariant
constructor
controller.
-
#variant_a? ⇒ Boolean
If the user is to be served variant A.
-
#variant_b? ⇒ Boolean
If the user is to be served variant B.
-
#variant_name ⇒ String
Get the bucket this user is in.
Constructor Details
#initialize(ab_test, request) ⇒ RequestedVariant
controller.
8 9 10 11 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 8 def initialize(ab_test, request) @ab_test = ab_test @request = request end |
Instance Attribute Details
#ab_test ⇒ Object (readonly)
Returns the value of attribute ab_test.
3 4 5 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 3 def ab_test @ab_test end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 3 def request @request end |
Instance Method Details
#analytics_meta_tag ⇒ String
HTML meta tag used to track the results of your experiment
41 42 43 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 41 def '<meta name="govuk:ab-test" content="' + ab_test. + ':' + variant_name + '">' end |
#configure_response(response) ⇒ Object
Configure the response
33 34 35 36 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 33 def configure_response(response) raise "We're trying to set the Vary header, but this would override the current header" if response.headers['Vary'] response.headers['Vary'] = ab_test.response_header end |
#variant_a? ⇒ Boolean
Returns if the user is to be served variant A.
21 22 23 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 21 def variant_a? variant_name == "A" end |
#variant_b? ⇒ Boolean
Returns if the user is to be served variant B.
26 27 28 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 26 def variant_b? variant_name == "B" end |
#variant_name ⇒ String
Get the bucket this user is in
16 17 18 |
# File 'lib/govuk_ab_testing/requested_variant.rb', line 16 def variant_name request.headers[ab_test.request_header] == "B" ? "B" : "A" end |