Class: BTAP::Visualization::GraphEmbedder

Inherits:
Object
  • Object
show all
Defined in:
lib/openstudio-standards/btap/visualization.rb

Constant Summary collapse

Embedded_Definition_Start =
"var EMBEDDED_ARRAY = "
Embedded_Function_Call =
"processEmbeddedArray(EMBEDDED_ARRAY);\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dest_file, html_file) ⇒ GraphEmbedder

This method sets the global parameters for the GraphicEmbedder destination file and html file.

Parameters:

  • dest_file (String)

    sets the global parameters for the GraphicEmbedder destination file

  • html_file (String)

    sets the global parameters for the GraphicEmbedder html file

Author:



35
36
37
38
# File 'lib/openstudio-standards/btap/visualization.rb', line 35

def initialize(dest_file,html_file)
  @destination_file = dest_file
  @html_file = html_file
end

Class Method Details

.get_array_as_string(csv_file) ⇒ string_array<String>

This method will return an array as a string.

Parameters:

  • csv_file (String)

    path to csv file

Returns:

Author:



60
61
62
63
64
65
# File 'lib/openstudio-standards/btap/visualization.rb', line 60

def self.get_array_as_string(csv_file)
  csv = CSV.open(csv_file,'r')
  string_array = csv.to_a.inspect
  string_array = string_array.sub(/nil/,"\"\"")
  return string_array
end

Instance Method Details

#create_embedding(csv_file) ⇒ Object

This method will create embedding.

Parameters:

  • csv_file (String)

    path to csv file

Author:



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/openstudio-standards/btap/visualization.rb', line 43

def create_embedding(csv_file)
  newfile = File.open(@destination_file, 'w')
  File.open(@html_file,'r').each do |line|
    if line.include? "!!Ruby Anchor!!"
      newfile.write(Embedded_Definition_Start + GraphEmbedder.get_array_as_string(csv_file) + ";\n")
      newfile.write(Embedded_Function_Call)
    else
      newfile.write(line)
    end
  end
  newfile.close
end