lib/openstudio/analysis/support_files.rb in openstudio-analysis-0.4.2 vs lib/openstudio/analysis/support_files.rb in openstudio-analysis-0.4.3
- old
+ new
@@ -2,11 +2,10 @@
# The most common use of support files are weather files, design day files, multiple seed files, worker initialization
# scripts, worker finalization scripts, and general libraries
module OpenStudio
module Analysis
class SupportFiles
-
attr_reader :files
# Create a new instance of the support file class
#
def initialize
@@ -22,28 +21,38 @@
fail "Path or file does not exist and cannot be added: #{path_or_filename}"
end
# only add if it isn't allready in the list
if @files.find_all { |f| f[:file] == path_or_filename }.empty?
- @files << {file: path_or_filename, metadata: metadata}
+ @files << { file: path_or_filename, metadata: metadata }
end
true
end
# Add a glob path with the same metadata for all the items
#
# @param pattern [String] Pattern to glob. example: /home/user1/files/**/*.rb
- # @return [Boolean] Returns false if the file does not exist
+ # @return [Boolean] Always returns true
def add_files(pattern, metadata = {})
Dir[pattern].each do |f|
add(f, metadata)
end
true
end
+ # Return the first
+ def first
+ @files.first
+ end
+
+ # Return the last
+ def last
+ @files.last
+ end
+
# Access a file by an index
def [](index)
@files[index]
end
@@ -64,13 +73,22 @@
# Iterate over the files
def each
@files.each { |i| yield i }
end
+ # Iterate over the files with index
+ def each_with_index
+ @files.each_with_index { |d, index| yield d, index }
+ end
+
# remove all the items
def clear
@files.clear
end
+ # find the first object. There has to be a better way to do this. Can I just inherit an array?
+ def find
+ @files.find { |i| yield i }
+ end
end
end
end