class Template::Html
This Class handles creating and writing HTML output files
Attributes
file_name[R]
Public Class Methods
new(dir, attr_labels)
click to toggle source
dir: basename of root directory attr_labels: array of attributes labels as strings
# File lib/template.rb, line 38 def initialize(dir, attr_labels) @file_name = "tmp/output/#{dir}_#{Time.now.to_i}.html" @file = File.new(@file_name, 'w') @template_path = set_template_path append_header(dir, attr_labels) end
Public Instance Methods
close()
click to toggle source
Writes footer to file and closes it
# File lib/template.rb, line 54 def close footer = File.read("#{@template_path}_footer.html.erb") partial = ERB.new(footer).result(binding) @file.write(partial) @file.close end
insert(img_attrs)
click to toggle source
Writes data row to file
# File lib/template.rb, line 46 def insert(img_attrs) @img_attrs = img_attrs row = File.read("#{@template_path}_row.html.erb") partial = ERB.new(row, nil, '-').result(binding) @file.write(partial) end
Private Instance Methods
append_header(dir, attr_labels)
click to toggle source
Writes the header component of the HTML file
# File lib/template.rb, line 75 def append_header(dir, attr_labels) @title = "Image GPS Scan for: #{dir}" @attr_labels = attr_labels header = File.read("#{@template_path}_header.html.erb") partial = ERB.new(header, nil, '-').result(binding) @file.write(partial) end
set_template_path()
click to toggle source
locate path to templates
# File lib/template.rb, line 64 def set_template_path template_path = 'lib/templates/html/' gem_path = "#{Gem.dir}/gems/gps_extractor-#{GpsExtractor::VERSION}/" if File.exists?(gem_path) return File.join(gem_path, template_path) else template_path end end