Class: Study

Inherits:
NesstarObject show all
Includes:
VariableContainer
Defined in:
lib/nesstar-api/study.rb

Overview

Represents a study

Constant Summary collapse

NSDSTAT =
"NSDSTAT"
SAS =
"SAS"
SPSS =
"SPSS"
SPSSPORT =
"SPSSPORT"
STATA =
"STATA"
STATA6 =
"STATA6"
STATA7 =
"STATA7"

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from VariableContainer

#get_variable_groups, #get_variables

Constructor Details

#initialize(data) ⇒ Study

Returns a new instance of Study.



22
23
24
25
26
27
# File 'lib/nesstar-api/study.rb', line 22

def initialize(data)
  @id = data['id']
  @name = data['name']
  @abstract = data['abstract']
  @last_update = data['updatedTimeStamp']
end

Instance Attribute Details

#abstractObject (readonly)

Returns the value of attribute abstract.



10
11
12
# File 'lib/nesstar-api/study.rb', line 10

def abstract
  @abstract
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/nesstar-api/study.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/nesstar-api/study.rb', line 10

def name
  @name
end

Instance Method Details

#correlateObject



50
51
# File 'lib/nesstar-api/study.rb', line 50

def correlate
end

#download(format, variables = [], case_subset = nil) ⇒ Object

Downloads the study (or parts of it) in different file formats.

The file will be a zip file containing one or more files depending on the requested format.

The format parameter should be one of the constants in this class.

To only download some variables, supply a list of the variables you wish.

The download can be further refined using a case subset. See nesstar-dev.nsd.uib.no/javadoc/com.nesstar/nesstar-api/0.6.5/com/nesstar/api/subset/CaseSubset.html#compile for more information.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/nesstar-api/study.rb', line 66

def download(format, variables = [], case_subset = nil)
  path = "study/#{@id}/download"

  query_string = ["format=" + format]
  query_string += collect_list(variables, "var", :id)
  query_string.push("caseSubset=" + case_subset) unless case_subset.nil?

  path += "?" + query_string.join('&')

  get_binary(path) do | data |
    if block_given?
      yield(data)
    else
      file = Tempfile.new("#{@name}.#{format}")
      file.write(data)
      file.close
      return file
    end
  end
end

#regressObject



53
54
# File 'lib/nesstar-api/study.rb', line 53

def regress
end

#tabulate(options) ⇒ Object

Returns a cross tabulation on this study

The options parameter holds the following data:



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/nesstar-api/study.rb', line 38

def tabulate(options)
  path = "study/#{@id}/tabulate/"
  query_string = prepare_query_string_for_tabulation options

  if query_string.length > 0
    path += "?" + query_string.join('&')
  end

  tabulation = get_values path
  Tabulation.new tabulation, options
end