Class: SPSS::Dictionary::Variable

Inherits:
Element show all
Defined in:
lib/spss.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Element

#add, #init_with, #parse_elements

Constructor Details

#initialize(config = {}) ⇒ Variable

Returns a new instance of Variable.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/spss.rb', line 80

def initialize(config={})
  super
  @@var_number||=1
  init_with({
    :aligment           =>  "left",
    :display_width      =>  8,
    :label              =>  "Variable #{@@var_number}",
    :measurement_level  =>  "SCALE",
    :name               =>  "var#{@@var_number}",
    :type               =>  0,
    :decimals           =>  2,
    :width              =>  10,
    :type_format        =>  "F",
    :labelset           => nil
  })
  init_with config
  @missing_values=[]
  @@var_number+=1
end

Instance Attribute Details

#aligmentObject

Returns the value of attribute aligment.



79
80
81
# File 'lib/spss.rb', line 79

def aligment
  @aligment
end

#decimalsObject

Returns the value of attribute decimals.



79
80
81
# File 'lib/spss.rb', line 79

def decimals
  @decimals
end

#display_widthObject

Returns the value of attribute display_width.



79
80
81
# File 'lib/spss.rb', line 79

def display_width
  @display_width
end

#labelObject

Returns the value of attribute label.



79
80
81
# File 'lib/spss.rb', line 79

def label
  @label
end

#labelsetObject

Returns the value of attribute labelset.



79
80
81
# File 'lib/spss.rb', line 79

def labelset
  @labelset
end

#measurement_levelObject

Returns the value of attribute measurement_level.



79
80
81
# File 'lib/spss.rb', line 79

def measurement_level
  @measurement_level
end

#missing_valuesObject

Returns the value of attribute missing_values.



79
80
81
# File 'lib/spss.rb', line 79

def missing_values
  @missing_values
end

#nameObject

Returns the value of attribute name.



79
80
81
# File 'lib/spss.rb', line 79

def name
  @name
end

#typeObject

Returns the value of attribute type.



79
80
81
# File 'lib/spss.rb', line 79

def type
  @type
end

#type_formatObject

Returns the value of attribute type_format.



79
80
81
# File 'lib/spss.rb', line 79

def type_format
  @type_format
end

#widthObject

Returns the value of attribute width.



79
80
81
# File 'lib/spss.rb', line 79

def width
  @width
end

Instance Method Details

#to_spssObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/spss.rb', line 104

def to_spss
  out=<<HERE
VARIABLE LABELS #{@name} '#{label}' .
VARIABLE ALIGMENT #{@name} (#{@aligment.upcase}) .
VARIABLE WIDTH #{@name} (#{@display_width}) .
VARIABLE LEVEL #{@name} (#{@measurement_level.upcase}) .
HERE
  if !@labelset.nil?
      out << "VALUE LABELS #{@name} "+labelset.parse_spss()+" ."
  end
  if @missing_values.size>0
      out << "MISSING VALUES #{@name} ("+@missing_values.collect{|m| m.data}.join(",")+") ."
  end
  out
end

#to_xmlObject



99
100
101
102
103
# File 'lib/spss.rb', line 99

def to_xml
  labelset_s=(@labelset.nil?) ? "":"\n"+@labelset.parse_xml(@name)
  missing_values=(@missing_values.size>0) ? @missing_values.collect {|m| m.to_xml}.join("\n"):""
  "<variable aligment='#{@aligment}' displayWidth='#{@display_width}' label='#{@label}' measurementLevel='#{@measurement_level}' name='#{@name}' type='#{@type}'>\n<variableFormat decimals='#{@decimals}' width='#{@width}' type='#{@type_format}' />\n"+parse_elements(:to_xml)+missing_values+"</variable>"+labelset_s
end