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

#initializeSupportFiles

Create a new instance of the support file class



16
17
18
# File 'lib/openstudio/analysis/support_files.rb', line 16

def initialize
  @files = []
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



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

def files
  @files
end

Instance Method Details

#[](index) ⇒ Object

Access a file by an index



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

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



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/openstudio/analysis/support_files.rb', line 29

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

Parameters:

  • pattern (String)

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

Returns:

  • (Boolean)

    Always returns true



46
47
48
49
50
51
52
# File 'lib/openstudio/analysis/support_files.rb', line 46

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

  true
end

#clearObject

remove all the items



94
95
96
# File 'lib/openstudio/analysis/support_files.rb', line 94

def clear
  @files.clear
end

#eachObject

Iterate over the files



84
85
86
# File 'lib/openstudio/analysis/support_files.rb', line 84

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

#each_with_indexObject

Iterate over the files with index



89
90
91
# File 'lib/openstudio/analysis/support_files.rb', line 89

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

#empty?Boolean

Check if the array is empty

Returns:

  • (Boolean)


21
22
23
# File 'lib/openstudio/analysis/support_files.rb', line 21

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?



99
100
101
# File 'lib/openstudio/analysis/support_files.rb', line 99

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

#firstObject

Return the first



55
56
57
# File 'lib/openstudio/analysis/support_files.rb', line 55

def first
  @files.first
end

#lastObject

Return the last



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

def last
  @files.last
end

#remove(filename) ⇒ Object

Remove a file from the list

Parameters:

  • filename (String)

    Full name of the file to remove



72
73
74
# File 'lib/openstudio/analysis/support_files.rb', line 72

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

#sizeInteger

Return the number of files

Returns:

  • (Integer)

    Number of items



79
80
81
# File 'lib/openstudio/analysis/support_files.rb', line 79

def size
  @files.size
end