openstudio-analysis 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,108 +1,108 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
3
- # See also https://openstudio.net/license
4
- # *******************************************************************************
5
-
6
- # OpenStudio::Analysis::ServerScripts is a container to hold the analysis and data_point server scripts.
7
- module OpenStudio
8
- module Analysis
9
- class ServerScripts
10
- attr_reader :files
11
-
12
- # Create a new instance of the Server Scripts file class
13
- # Server scripts are run at either the analysis or data_point level and are either initialization or finalization
14
- # file: full path to the script
15
- # arguments: array of arguments for the script
16
- # init_or_final: specify either 'initialization' or 'finalization'
17
- # server_or_data_point: specify either 'analysis' or 'data_point'
18
- #
19
- def initialize
20
- @files = []
21
- end
22
-
23
- def add(file, arguments, init_or_final = 'initialization', server_or_data_point = 'data_point')
24
-
25
- file_path = File.expand_path(file)
26
- if !File.exist?(file_path)
27
- raise ArgumentError, "File at '#{file_path}' does not exist"
28
- end
29
-
30
- if init_or_final != 'initialization' && init_or_final != 'finalization'
31
- raise ArgumentError, "init_or_final must be 'initialization' or 'finalization'"
32
- end
33
-
34
- if server_or_data_point != 'analysis' && server_or_data_point != 'data_point'
35
- raise ArgumentError, "server_or_data_point must be 'analysis' or 'data_point'"
36
- end
37
-
38
- if !arguments.is_a?(Array)
39
- raise ArgumentError, "arguments must be an array"
40
- end
41
-
42
- file = {
43
- file: file_path,
44
- arguments: arguments,
45
- init_or_final: init_or_final,
46
- server_or_data_point: server_or_data_point
47
- }
48
- @files << file
49
- true
50
- end
51
-
52
- # Check if the array is empty
53
- def empty?
54
- @files.empty?
55
- end
56
-
57
- # Return the first
58
- def first
59
- @files.first
60
- end
61
-
62
- # Return the last
63
- def last
64
- @files.last
65
- end
66
-
67
- # Access a file by an index
68
- def [](index)
69
- @files[index]
70
- end
71
-
72
- # Remove a file from the list
73
- #
74
- # @param filename [String] Full name of the file to remove
75
- def remove(filename)
76
- @files.delete_if { |f| f[:file] == filename }
77
- end
78
-
79
- # Return the number of files
80
- #
81
- # @return [Integer] Number of items
82
- def size
83
- @files.size
84
- end
85
-
86
- # Iterate over the files
87
- def each
88
- @files.each { |i| yield i }
89
- end
90
-
91
- # Iterate over the files with index
92
- def each_with_index
93
- @files.each_with_index { |d, index| yield d, index }
94
- end
95
-
96
- # remove all the items
97
- def clear
98
- @files.clear
99
- end
100
-
101
- # find the first object. There has to be a better way to do this. Can I just inherit an array?
102
- def find
103
- @files.find { |i| yield i }
104
- end
105
-
106
- end
107
- end
108
- end
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
3
+ # See also https://openstudio.net/license
4
+ # *******************************************************************************
5
+
6
+ # OpenStudio::Analysis::ServerScripts is a container to hold the analysis and data_point server scripts.
7
+ module OpenStudio
8
+ module Analysis
9
+ class ServerScripts
10
+ attr_reader :files
11
+
12
+ # Create a new instance of the Server Scripts file class
13
+ # Server scripts are run at either the analysis or data_point level and are either initialization or finalization
14
+ # file: full path to the script
15
+ # arguments: array of arguments for the script
16
+ # init_or_final: specify either 'initialization' or 'finalization'
17
+ # server_or_data_point: specify either 'analysis' or 'data_point'
18
+ #
19
+ def initialize
20
+ @files = []
21
+ end
22
+
23
+ def add(file, arguments, init_or_final = 'initialization', server_or_data_point = 'data_point')
24
+
25
+ file_path = File.expand_path(file)
26
+ if !File.exist?(file_path)
27
+ raise ArgumentError, "File at '#{file_path}' does not exist"
28
+ end
29
+
30
+ if init_or_final != 'initialization' && init_or_final != 'finalization'
31
+ raise ArgumentError, "init_or_final must be 'initialization' or 'finalization'"
32
+ end
33
+
34
+ if server_or_data_point != 'analysis' && server_or_data_point != 'data_point'
35
+ raise ArgumentError, "server_or_data_point must be 'analysis' or 'data_point'"
36
+ end
37
+
38
+ if !arguments.is_a?(Array)
39
+ raise ArgumentError, "arguments must be an array"
40
+ end
41
+
42
+ file = {
43
+ file: file_path,
44
+ arguments: arguments,
45
+ init_or_final: init_or_final,
46
+ server_or_data_point: server_or_data_point
47
+ }
48
+ @files << file
49
+ true
50
+ end
51
+
52
+ # Check if the array is empty
53
+ def empty?
54
+ @files.empty?
55
+ end
56
+
57
+ # Return the first
58
+ def first
59
+ @files.first
60
+ end
61
+
62
+ # Return the last
63
+ def last
64
+ @files.last
65
+ end
66
+
67
+ # Access a file by an index
68
+ def [](index)
69
+ @files[index]
70
+ end
71
+
72
+ # Remove a file from the list
73
+ #
74
+ # @param filename [String] Full name of the file to remove
75
+ def remove(filename)
76
+ @files.delete_if { |f| f[:file] == filename }
77
+ end
78
+
79
+ # Return the number of files
80
+ #
81
+ # @return [Integer] Number of items
82
+ def size
83
+ @files.size
84
+ end
85
+
86
+ # Iterate over the files
87
+ def each
88
+ @files.each { |i| yield i }
89
+ end
90
+
91
+ # Iterate over the files with index
92
+ def each_with_index
93
+ @files.each_with_index { |d, index| yield d, index }
94
+ end
95
+
96
+ # remove all the items
97
+ def clear
98
+ @files.clear
99
+ end
100
+
101
+ # find the first object. There has to be a better way to do this. Can I just inherit an array?
102
+ def find
103
+ @files.find { |i| yield i }
104
+ end
105
+
106
+ end
107
+ end
108
+ end
@@ -1,104 +1,104 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
3
- # See also https://openstudio.net/license
4
- # *******************************************************************************
5
-
6
- # OpenStudio::Analysis::SupportFiles is a container to hold other analysis files that may need to be packaged.
7
- # The most common use of support files are weather files, design day files, multiple seed files, worker initialization
8
- # scripts, worker finalization scripts, and general libraries
9
- module OpenStudio
10
- module Analysis
11
- class SupportFiles
12
- attr_reader :files
13
-
14
- # Create a new instance of the support file class
15
- #
16
- def initialize
17
- @files = []
18
- end
19
-
20
- # Check if the array is empty
21
- def empty?
22
- @files.empty?
23
- end
24
-
25
- # Add a file to the support file list
26
- #
27
- # @param path_or_filename [String] Full path of the file to be added.
28
- # @return [Boolean] Returns false if the file does not exist
29
- def add(path_or_filename, metadata = {})
30
- if !File.exist?(path_or_filename) && !Dir.exist?(path_or_filename)
31
- raise "Path or file does not exist and cannot be added: #{path_or_filename}"
32
- end
33
-
34
- # only add if it isn't allready in the list
35
- if @files.find_all { |f| f[:file] == path_or_filename }.empty?
36
- @files << { file: path_or_filename, metadata: metadata }
37
- end
38
-
39
- true
40
- end
41
-
42
- # Add a glob path with the same metadata for all the items
43
- #
44
- # @param pattern [String] Pattern to glob. example: /home/user1/files/**/*.rb
45
- # @return [Boolean] Always returns true
46
- def add_files(pattern, metadata = {})
47
- Dir[pattern].each do |f|
48
- add(f, metadata)
49
- end
50
-
51
- true
52
- end
53
-
54
- # Return the first
55
- def first
56
- @files.first
57
- end
58
-
59
- # Return the last
60
- def last
61
- @files.last
62
- end
63
-
64
- # Access a file by an index
65
- def [](index)
66
- @files[index]
67
- end
68
-
69
- # Remove a file from the list
70
- #
71
- # @param filename [String] Full name of the file to remove
72
- def remove(filename)
73
- @files.delete_if { |f| f[:file] == filename }
74
- end
75
-
76
- # Return the number of files
77
- #
78
- # @return [Integer] Number of items
79
- def size
80
- @files.size
81
- end
82
-
83
- # Iterate over the files
84
- def each
85
- @files.each { |i| yield i }
86
- end
87
-
88
- # Iterate over the files with index
89
- def each_with_index
90
- @files.each_with_index { |d, index| yield d, index }
91
- end
92
-
93
- # remove all the items
94
- def clear
95
- @files.clear
96
- end
97
-
98
- # find the first object. There has to be a better way to do this. Can I just inherit an array?
99
- def find
100
- @files.find { |i| yield i }
101
- end
102
- end
103
- end
104
- end
1
+ # *******************************************************************************
2
+ # OpenStudio(R), Copyright (c) Alliance for Sustainable Energy, LLC.
3
+ # See also https://openstudio.net/license
4
+ # *******************************************************************************
5
+
6
+ # OpenStudio::Analysis::SupportFiles is a container to hold other analysis files that may need to be packaged.
7
+ # The most common use of support files are weather files, design day files, multiple seed files, worker initialization
8
+ # scripts, worker finalization scripts, and general libraries
9
+ module OpenStudio
10
+ module Analysis
11
+ class SupportFiles
12
+ attr_reader :files
13
+
14
+ # Create a new instance of the support file class
15
+ #
16
+ def initialize
17
+ @files = []
18
+ end
19
+
20
+ # Check if the array is empty
21
+ def empty?
22
+ @files.empty?
23
+ end
24
+
25
+ # Add a file to the support file list
26
+ #
27
+ # @param path_or_filename [String] Full path of the file to be added.
28
+ # @return [Boolean] Returns false if the file does not exist
29
+ def add(path_or_filename, metadata = {})
30
+ if !File.exist?(path_or_filename) && !Dir.exist?(path_or_filename)
31
+ raise "Path or file does not exist and cannot be added: #{path_or_filename}"
32
+ end
33
+
34
+ # only add if it isn't allready in the list
35
+ if @files.find_all { |f| f[:file] == path_or_filename }.empty?
36
+ @files << { file: path_or_filename, metadata: metadata }
37
+ end
38
+
39
+ true
40
+ end
41
+
42
+ # Add a glob path with the same metadata for all the items
43
+ #
44
+ # @param pattern [String] Pattern to glob. example: /home/user1/files/**/*.rb
45
+ # @return [Boolean] Always returns true
46
+ def add_files(pattern, metadata = {})
47
+ Dir[pattern].each do |f|
48
+ add(f, metadata)
49
+ end
50
+
51
+ true
52
+ end
53
+
54
+ # Return the first
55
+ def first
56
+ @files.first
57
+ end
58
+
59
+ # Return the last
60
+ def last
61
+ @files.last
62
+ end
63
+
64
+ # Access a file by an index
65
+ def [](index)
66
+ @files[index]
67
+ end
68
+
69
+ # Remove a file from the list
70
+ #
71
+ # @param filename [String] Full name of the file to remove
72
+ def remove(filename)
73
+ @files.delete_if { |f| f[:file] == filename }
74
+ end
75
+
76
+ # Return the number of files
77
+ #
78
+ # @return [Integer] Number of items
79
+ def size
80
+ @files.size
81
+ end
82
+
83
+ # Iterate over the files
84
+ def each
85
+ @files.each { |i| yield i }
86
+ end
87
+
88
+ # Iterate over the files with index
89
+ def each_with_index
90
+ @files.each_with_index { |d, index| yield d, index }
91
+ end
92
+
93
+ # remove all the items
94
+ def clear
95
+ @files.clear
96
+ end
97
+
98
+ # find the first object. There has to be a better way to do this. Can I just inherit an array?
99
+ def find
100
+ @files.find { |i| yield i }
101
+ end
102
+ end
103
+ end
104
+ end