Class: UniqueResponse::Response
- Inherits:
-
Struct
- Object
- Struct
- UniqueResponse::Response
- Defined in:
- lib/unique_response_ruby/response.rb
Instance Attribute Summary collapse
-
#ip_address ⇒ Object
Returns the value of attribute ip_address.
-
#matches ⇒ Object
readonly
Returns the value of attribute matches.
-
#panelist_id ⇒ Object
Returns the value of attribute panelist_id.
-
#respondent_id ⇒ Object
Returns the value of attribute respondent_id.
-
#survey_token ⇒ Object
Returns the value of attribute survey_token.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #duplicate_ip_address? ⇒ Boolean
- #duplicate_ip_and_ua? ⇒ Boolean
- #duplicate_user_agent? ⇒ Boolean
- #save ⇒ Object
- #valid? ⇒ Boolean
Instance Attribute Details
#ip_address ⇒ Object
Returns the value of attribute ip_address
3 4 5 |
# File 'lib/unique_response_ruby/response.rb', line 3 def ip_address @ip_address end |
#matches ⇒ Object (readonly)
Returns the value of attribute matches.
4 5 6 |
# File 'lib/unique_response_ruby/response.rb', line 4 def matches @matches end |
#panelist_id ⇒ Object
Returns the value of attribute panelist_id
3 4 5 |
# File 'lib/unique_response_ruby/response.rb', line 3 def panelist_id @panelist_id end |
#respondent_id ⇒ Object
Returns the value of attribute respondent_id
3 4 5 |
# File 'lib/unique_response_ruby/response.rb', line 3 def respondent_id @respondent_id end |
#survey_token ⇒ Object
Returns the value of attribute survey_token
3 4 5 |
# File 'lib/unique_response_ruby/response.rb', line 3 def survey_token @survey_token end |
#user_agent ⇒ Object
Returns the value of attribute user_agent
3 4 5 |
# File 'lib/unique_response_ruby/response.rb', line 3 def user_agent @user_agent end |
Instance Method Details
#duplicate_ip_address? ⇒ Boolean
22 23 24 |
# File 'lib/unique_response_ruby/response.rb', line 22 def duplicate_ip_address? @matches.any? { |match| match["ip_address"] == ip_address } end |
#duplicate_ip_and_ua? ⇒ Boolean
30 31 32 |
# File 'lib/unique_response_ruby/response.rb', line 30 def duplicate_ip_and_ua? @matches.any? { |match| match["ip_address"] == ip_address && match["user_agent"] == user_agent } end |
#duplicate_user_agent? ⇒ Boolean
26 27 28 |
# File 'lib/unique_response_ruby/response.rb', line 26 def duplicate_user_agent? @matches.any? { |match| match["user_agent"] == user_agent } end |
#save ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/unique_response_ruby/response.rb', line 10 def save raise ArgumentError unless valid? client = Client.new if client.save_response(self) @matches = client.data true else false end end |
#valid? ⇒ Boolean
6 7 8 |
# File 'lib/unique_response_ruby/response.rb', line 6 def valid? values.map { |value| value.is_a?(String) && !value.empty? }.reduce(:&) end |