Class: OpenStudio::Analysis::SupportFiles
- Inherits:
-
Object
- Object
- OpenStudio::Analysis::SupportFiles
- Defined in:
- lib/openstudio/analysis/support_files.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Access a file by an index.
-
#add(path_or_filename, metadata = {}) ⇒ Boolean
Add a file to the support file list.
-
#add_files(pattern, metadata = {}) ⇒ Boolean
Add a glob path with the same metadata for all the items.
-
#clear ⇒ Object
remove all the items.
-
#each ⇒ Object
Iterate over the files.
-
#each_with_index ⇒ Object
Iterate over the files with index.
-
#empty? ⇒ Boolean
Check if the array is empty.
-
#find ⇒ Object
find the first object.
-
#first ⇒ Object
Return the first.
-
#initialize ⇒ SupportFiles
constructor
Create a new instance of the support file class.
-
#last ⇒ Object
Return the last.
-
#remove(filename) ⇒ Object
Remove a file from the list.
-
#size ⇒ Integer
Return the number of files.
Constructor Details
#initialize ⇒ SupportFiles
Create a new instance of the support file class
46 47 48 |
# File 'lib/openstudio/analysis/support_files.rb', line 46 def initialize @files = [] end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
42 43 44 |
# File 'lib/openstudio/analysis/support_files.rb', line 42 def files @files end |
Instance Method Details
#[](index) ⇒ Object
Access a file by an index
95 96 97 |
# File 'lib/openstudio/analysis/support_files.rb', line 95 def [](index) @files[index] end |
#add(path_or_filename, metadata = {}) ⇒ Boolean
Add a file to the support file list
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/openstudio/analysis/support_files.rb', line 59 def add(path_or_filename, = {}) if !File.exist?(path_or_filename) && !Dir.exist?(path_or_filename) raise "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: } end true end |
#add_files(pattern, metadata = {}) ⇒ Boolean
Add a glob path with the same metadata for all the items
76 77 78 79 80 81 82 |
# File 'lib/openstudio/analysis/support_files.rb', line 76 def add_files(pattern, = {}) Dir[pattern].each do |f| add(f, ) end true end |
#clear ⇒ Object
remove all the items
124 125 126 |
# File 'lib/openstudio/analysis/support_files.rb', line 124 def clear @files.clear end |
#each ⇒ Object
Iterate over the files
114 115 116 |
# File 'lib/openstudio/analysis/support_files.rb', line 114 def each @files.each { |i| yield i } end |
#each_with_index ⇒ Object
Iterate over the files with index
119 120 121 |
# File 'lib/openstudio/analysis/support_files.rb', line 119 def each_with_index @files.each_with_index { |d, index| yield d, index } end |
#empty? ⇒ Boolean
Check if the array is empty
51 52 53 |
# File 'lib/openstudio/analysis/support_files.rb', line 51 def empty? @files.empty? end |
#find ⇒ Object
find the first object. There has to be a better way to do this. Can I just inherit an array?
129 130 131 |
# File 'lib/openstudio/analysis/support_files.rb', line 129 def find @files.find { |i| yield i } end |
#first ⇒ Object
Return the first
85 86 87 |
# File 'lib/openstudio/analysis/support_files.rb', line 85 def first @files.first end |
#last ⇒ Object
Return the last
90 91 92 |
# File 'lib/openstudio/analysis/support_files.rb', line 90 def last @files.last end |
#remove(filename) ⇒ Object
Remove a file from the list
102 103 104 |
# File 'lib/openstudio/analysis/support_files.rb', line 102 def remove(filename) @files.delete_if { |f| f[:file] == filename } end |
#size ⇒ Integer
Return the number of files
109 110 111 |
# File 'lib/openstudio/analysis/support_files.rb', line 109 def size @files.size end |