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’



49
50
51
# File 'lib/openstudio/analysis/server_scripts.rb', line 49

def initialize
  @files = []
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



40
41
42
# File 'lib/openstudio/analysis/server_scripts.rb', line 40

def files
  @files
end

Instance Method Details

#[](index) ⇒ Object

Access a file by an index



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

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

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/openstudio/analysis/server_scripts.rb', line 53

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



127
128
129
# File 'lib/openstudio/analysis/server_scripts.rb', line 127

def clear
  @files.clear
end

#eachObject

Iterate over the files



117
118
119
# File 'lib/openstudio/analysis/server_scripts.rb', line 117

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

#each_with_indexObject

Iterate over the files with index



122
123
124
# File 'lib/openstudio/analysis/server_scripts.rb', line 122

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

#empty?Boolean

Check if the array is empty

Returns:

  • (Boolean)


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

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?



132
133
134
# File 'lib/openstudio/analysis/server_scripts.rb', line 132

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

#firstObject

Return the first



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

def first
  @files.first
end

#lastObject

Return the last



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

def last
  @files.last
end

#remove(filename) ⇒ Object

Remove a file from the list

Parameters:

  • filename (String)

    Full name of the file to remove



105
106
107
# File 'lib/openstudio/analysis/server_scripts.rb', line 105

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

#sizeInteger

Return the number of files

Returns:

  • (Integer)

    Number of items



112
113
114
# File 'lib/openstudio/analysis/server_scripts.rb', line 112

def size
  @files.size
end