Class: OpenStudio::Analysis::SupportFiles

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ SupportFiles

Create a new instance of the support file class



12
13
14
# File 'lib/openstudio/analysis/support_files.rb', line 12

def initialize
  @files = []
end

Instance Attribute Details

#files ⇒ Object (readonly)

Returns the value of attribute files.



8
9
10
# File 'lib/openstudio/analysis/support_files.rb', line 8

def files
  @files
end

Instance Method Details

#[](index) ⇒ Object

Access a file by an index



46
47
48
# File 'lib/openstudio/analysis/support_files.rb', line 46

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

#add(path_or_filename, metadata = {}) ⇒ Boolean

Add a file to the support file list

Parameters:

  • path_or_filename (String) —

    Full path of the file to be added.

Returns:

  • (Boolean) —

    Returns false if the file does not exist



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/openstudio/analysis/support_files.rb', line 20

def add(path_or_filename,  = {})
  if !File.exist?(path_or_filename) && !Dir.exist?(path_or_filename)
    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: }
  end

  true
end

#add_files(pattern, metadata = {}) ⇒ Boolean

Add a glob path with the same metadata for all the items

Parameters:

  • pattern (String) —

    Pattern to glob. example: /home/user1/files/**/*.rb

Returns:

  • (Boolean) —

    Returns false if the file does not exist



37
38
39
40
41
42
43
# File 'lib/openstudio/analysis/support_files.rb', line 37

def add_files(pattern,  = {})
  Dir[pattern].each do |f|
    add(f, )
  end

  true
end

#clear ⇒ Object

remove all the items



70
71
72
# File 'lib/openstudio/analysis/support_files.rb', line 70

def clear
  @files.clear
end

#each ⇒ Object

Iterate over the files



65
66
67
# File 'lib/openstudio/analysis/support_files.rb', line 65

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

#remove(filename) ⇒ Object

Remove a file from the list

Parameters:

  • filename (String) —

    Full name of the file to remove



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

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

#size ⇒ Integer

Return the number of files

Returns:

  • (Integer) —

    Number of items



60
61
62
# File 'lib/openstudio/analysis/support_files.rb', line 60

def size
  @files.size
end