Class: Statsample::Analysis::Suite

Inherits:
Object
  • Object
show all
Includes:
Shorthand
Defined in:
lib/statsample/analysis/suite.rb

Direct Known Subclasses

SuiteReportBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Shorthand

#cor, #cov, #dataset, #dominance_analysis, #dominance_analysis_bootstrap, #levene, #lr, #multiscale_analysis, #names, #pca, #polychoric, #principal_axis, #read_csv, #read_excel, rnorm, #scale_analysis, #skill_scale_analysis, test_u, #tetrachoric, #vector

Constructor Details

#initialize(opts = Hash.new(), &block) ⇒ Suite


8
9
10
11
12
13
14
15
16
17
# File 'lib/statsample/analysis/suite.rb', line 8

def initialize(opts=Hash.new(), &block)
  if !opts.is_a? Hash
    opts={:name=>opts}
  end
   
  @block=block
  @name=opts[:name] || "Analysis #{Time.now}"
  @attached=[]
  @output=opts[:output] || ::STDOUT
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object


81
82
83
84
85
86
# File 'lib/statsample/analysis/suite.rb', line 81

def method_missing(name, *args,&block)
  @attached.reverse.each do |ds|
    return ds[name] if ds.vectors.to_a.include? (name)
  end
  raise "Method #{name} doesn't exists"
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block


7
8
9
# File 'lib/statsample/analysis/suite.rb', line 7

def block
  @block
end

#nameObject

Returns the value of attribute name


6
7
8
# File 'lib/statsample/analysis/suite.rb', line 6

def name
  @name
end

#outputObject

Returns the value of attribute output


5
6
7
# File 'lib/statsample/analysis/suite.rb', line 5

def output
  @output
end

Instance Method Details

#add_to_reportbuilder(rb) ⇒ Object


34
35
36
# File 'lib/statsample/analysis/suite.rb', line 34

def add_to_reportbuilder(rb)
  SuiteReportBuilder.new({:name=>name, :rb=>rb}, &block)
end

#attach(ds) ⇒ Object


47
48
49
# File 'lib/statsample/analysis/suite.rb', line 47

def attach(ds)
  @attached.push(ds)
end

#boxplot(*args) ⇒ Object


71
72
73
# File 'lib/statsample/analysis/suite.rb', line 71

def boxplot(*args)
  show_svg(old_boxplot(*args).to_svg)
end

#desc(d) ⇒ Object

Provides a description of the procedure. Only appears as a commentary on SuiteReportBuilder outputs


24
25
26
27
# File 'lib/statsample/analysis/suite.rb', line 24

def desc(d)
  @output.puts("Description:")
  @output.puts("  #{d}") 
end

#detach(ds = nil) ⇒ Object


50
51
52
53
54
55
56
# File 'lib/statsample/analysis/suite.rb', line 50

def detach(ds=nil)
  if ds.nil?
    @attached.pop
  else
    @attached.delete(ds)
  end
end

#echo(*args) ⇒ Object


28
29
30
# File 'lib/statsample/analysis/suite.rb', line 28

def echo(*args)
  @output.puts(*args)
end

#generate(filename) ⇒ Object


38
39
40
41
# File 'lib/statsample/analysis/suite.rb', line 38

def generate(filename)
  ar=SuiteReportBuilder.new({:name=>name}, &block)
  ar.generate(filename)
end

#histogram(*args) ⇒ Object


74
75
76
# File 'lib/statsample/analysis/suite.rb', line 74

def histogram(*args)
  show_svg(old_histogram(*args).to_svg)
end

#old_boxplotObject


57
# File 'lib/statsample/analysis/suite.rb', line 57

alias :old_boxplot :boxplot

#old_histogramObject


58
# File 'lib/statsample/analysis/suite.rb', line 58

alias :old_histogram :histogram

#old_scatterplotObject


59
# File 'lib/statsample/analysis/suite.rb', line 59

alias :old_scatterplot :scatterplot

#runObject

Run the analysis, putting output on


19
20
21
# File 'lib/statsample/analysis/suite.rb', line 19

def run
   @block.arity<1 ? instance_eval(&@block) : @block.call(self)
end

#scatterplot(*args) ⇒ Object


77
78
79
# File 'lib/statsample/analysis/suite.rb', line 77

def scatterplot(*args)
  show_svg(old_scatterplot(*args).to_svg)
end

#show_svg(svg) ⇒ Object


61
62
63
64
65
66
67
68
69
70
# File 'lib/statsample/analysis/suite.rb', line 61

def show_svg(svg)
  require 'tmpdir'
  fn=Dir.tmpdir+"/image_#{Time.now.to_f}.svg"
  File.open(fn,"w") {|fp| fp.write svg}
	if RUBY_PLATFORM =~/darwin/
	  %x(open -a safari #{fn})
	else
	  %x(xdg-open #{fn})
	end
end

#summary(obj) ⇒ Object


31
32
33
# File 'lib/statsample/analysis/suite.rb', line 31

def summary(obj)
  obj.summary
end

#to_textObject


42
43
44
45
# File 'lib/statsample/analysis/suite.rb', line 42

def to_text
  ar=SuiteReportBuilder.new({:name=>name}, &block)
  ar.to_text
end