Class: OpenStudio::Analysis::ServerScripts

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio/analysis/server_scripts.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServerScripts

Create a new instance of the Server Scripts file class Server scripts are run at either the analysis or data_point level and are either initialization or finalization file: full path to the script arguments: array of arguments for the script init_or_final: specify either ‘initialization’ or ‘finalization’ server_or_data_point: specify either ‘analysis’ or ‘data_point’



19
20
21
# File 'lib/openstudio/analysis/server_scripts.rb', line 19

def initialize
  @files = []
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



10
11
12
# File 'lib/openstudio/analysis/server_scripts.rb', line 10

def files
  @files
end

Instance Method Details

#[](index) ⇒ Object

Access a file by an index



68
69
70
# File 'lib/openstudio/analysis/server_scripts.rb', line 68

def [](index)
  @files[index]
end

#add(file, arguments, init_or_final = 'initialization', server_or_data_point = 'data_point') ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/openstudio/analysis/server_scripts.rb', line 23

def add(file, arguments, init_or_final = 'initialization', server_or_data_point = 'data_point')

  file_path = File.expand_path(file)
  if !File.exist?(file_path)
    raise ArgumentError, "File at '#{file_path}' does not exist"
  end
    
  if init_or_final != 'initialization' && init_or_final != 'finalization'
    raise ArgumentError, "init_or_final must be 'initialization' or 'finalization'"
  end
  
  if server_or_data_point != 'analysis' && server_or_data_point != 'data_point'
    raise ArgumentError, "server_or_data_point must be 'analysis' or 'data_point'"
  end
  
  if !arguments.is_a?(Array)
    raise ArgumentError, "arguments must be an array"
  end
    
  file = {
    file: file_path,
    arguments: arguments,
    init_or_final: init_or_final,
    server_or_data_point: server_or_data_point
  }
  @files << file
  true
end

#clearObject

remove all the items



97
98
99
# File 'lib/openstudio/analysis/server_scripts.rb', line 97

def clear
  @files.clear
end

#eachObject

Iterate over the files



87
88
89
# File 'lib/openstudio/analysis/server_scripts.rb', line 87

def each
  @files.each { |i| yield i }
end

#each_with_indexObject

Iterate over the files with index



92
93
94
# File 'lib/openstudio/analysis/server_scripts.rb', line 92

def each_with_index
  @files.each_with_index { |d, index| yield d, index }
end

#empty?Boolean

Check if the array is empty

Returns:

  • (Boolean)


53
54
55
# File 'lib/openstudio/analysis/server_scripts.rb', line 53

def empty?
  @files.empty?
end

#findObject

find the first object. There has to be a better way to do this. Can I just inherit an array?



102
103
104
# File 'lib/openstudio/analysis/server_scripts.rb', line 102

def find
  @files.find { |i| yield i }
end

#firstObject

Return the first



58
59
60
# File 'lib/openstudio/analysis/server_scripts.rb', line 58

def first
  @files.first
end

#lastObject

Return the last



63
64
65
# File 'lib/openstudio/analysis/server_scripts.rb', line 63

def last
  @files.last
end

#remove(filename) ⇒ Object

Remove a file from the list

Parameters:

  • filename (String)

    Full name of the file to remove



75
76
77
# File 'lib/openstudio/analysis/server_scripts.rb', line 75

def remove(filename)
  @files.delete_if { |f| f[:file] == filename }
end

#sizeInteger

Return the number of files

Returns:

  • (Integer)

    Number of items



82
83
84
# File 'lib/openstudio/analysis/server_scripts.rb', line 82

def size
  @files.size
end