Class: UniqueResponse::Response

Inherits:
Struct
  • Object
show all
Defined in:
lib/unique_response_ruby/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ip_addressObject

Returns the value of attribute ip_address

Returns:

  • (Object)

    the current value of ip_address



3
4
5
# File 'lib/unique_response_ruby/response.rb', line 3

def ip_address
  @ip_address
end

#matchesObject (readonly)

Returns the value of attribute matches.



4
5
6
# File 'lib/unique_response_ruby/response.rb', line 4

def matches
  @matches
end

#panelist_idObject

Returns the value of attribute panelist_id

Returns:

  • (Object)

    the current value of panelist_id



3
4
5
# File 'lib/unique_response_ruby/response.rb', line 3

def panelist_id
  @panelist_id
end

#respondent_idObject

Returns the value of attribute respondent_id

Returns:

  • (Object)

    the current value of respondent_id



3
4
5
# File 'lib/unique_response_ruby/response.rb', line 3

def respondent_id
  @respondent_id
end

#survey_tokenObject

Returns the value of attribute survey_token

Returns:

  • (Object)

    the current value of survey_token



3
4
5
# File 'lib/unique_response_ruby/response.rb', line 3

def survey_token
  @survey_token
end

#user_agentObject

Returns the value of attribute user_agent

Returns:

  • (Object)

    the current value of 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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

#saveObject

Raises:

  • (ArgumentError)


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

Returns:

  • (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