Class: QualtricsAPI::SurveyCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/qualtrics_api/survey_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SurveyCollection

Returns a new instance of SurveyCollection.



13
14
15
16
17
# File 'lib/qualtrics_api/survey_collection.rb', line 13

def initialize(options = {})
  @conn = options[:connection]
  @scope_id = options[:scope_id]
  @all = []
end

Instance Attribute Details

#allObject (readonly)

Returns the value of attribute all.



8
9
10
# File 'lib/qualtrics_api/survey_collection.rb', line 8

def all
  @all
end

#scope_idObject

Returns the value of attribute scope_id.



7
8
9
# File 'lib/qualtrics_api/survey_collection.rb', line 7

def scope_id
  @scope_id
end

Instance Method Details

#[](survey_id) ⇒ Object



36
# File 'lib/qualtrics_api/survey_collection.rb', line 36

def [](survey_id); find(survey_id); end

#fetch(options = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/qualtrics_api/survey_collection.rb', line 19

def fetch(options = {})
  @all = []
  update_query_attributes(options)
  parse_fetch_response(@conn.get('surveys', query_params))
  self
end

#find(survey_id) ⇒ Object



37
38
39
40
41
# File 'lib/qualtrics_api/survey_collection.rb', line 37

def find(survey_id)
  @all.select do |survey|
    survey.id == survey_id
  end.first || QualtricsAPI::Survey.new("id" => survey_id , connection: @conn)
end

#query_attributesObject



26
27
28
29
30
# File 'lib/qualtrics_api/survey_collection.rb', line 26

def query_attributes
  {
    :scope_id => @scope_id
  }
end

#update_query_attributes(new_attributes = {}) ⇒ Object



32
33
34
# File 'lib/qualtrics_api/survey_collection.rb', line 32

def update_query_attributes(new_attributes = {})
  @scope_id = new_attributes[:scope_id] if new_attributes.has_key? :scope_id
end