class EnergyPlus::EpImfFile
Attributes
locations[RW]
Public Class Methods
new(path)
click to toggle source
# File lib/energyplus/EpImfFile.rb, line 25 def initialize(path) puts 'parsing ' + path @path = path.expand_path @text = '' @locations = [] if @path.exist? File.open(@path) do |f| @text << f.read parse end end end
Public Instance Methods
location_sort(x,y)
click to toggle source
# File lib/energyplus/EpImfFile.rb, line 77 def location_sort(x,y) if x[0].include?('ShowHeader') return -1 elsif y[0].include?('ShowHeader') return 1 else return x[0] <=> y[0] end end
parse()
click to toggle source
# File lib/energyplus/EpImfFile.rb, line 50 def parse this_text = @text locations = Hash.new regex = /##def.*?##enddef/im while match_data = this_text.match(regex) #Grab the name of the location regex2 = /##def (.*?)\[\]$/im location_name = match_data.to_s.match(regex2)[1].lstrip.rstrip #remove the header/footer from imf snippet regex3 = /##def (.*?)\[\]\n*/im regex4 = /##enddef(.*)\n*/im imf_data = match_data.to_s.gsub(regex3, "").gsub(regex4, "") #clean up the IMF (which is really idf data at this point) imf_data.gsub!(/^( )/,"") location = [location_name, imf_data] @locations.push(location) this_text = match_data.post_match end end
savefileas(path)
click to toggle source
# File lib/energyplus/EpImfFile.rb, line 39 def savefileas(path) File.open(path, "w") do |f| @locations.each do |loc| f << "##def " + loc[0] + "[]\n" f << loc[1] f << "##enddef\n\n" end end end
sort()
click to toggle source
# File lib/energyplus/EpImfFile.rb, line 87 def sort @locations.sort! {|x,y| location_sort(x,y)} end