Class: HashThatTree::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/display.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, error_data, *file_data) ⇒ Display

initialize the class with the folders to be compared



17
18
19
20
21
22
23
# File 'lib/display.rb', line 17

def initialize(options, error_data, *file_data )
	   @format = options['output']
	   @displayerrors = options['errors']
	   @file_data = file_data
	   @error_data = error_data
	   p @error_data
end

Instance Attribute Details

#error_dataObject

array of files that could not be processed



14
15
16
# File 'lib/display.rb', line 14

def error_data
  @error_data
end

#file_dataObject

array of files and associated hashes



13
14
15
# File 'lib/display.rb', line 13

def file_data
  @file_data
end

#formatObject

the format to output the results to. csv, html or json



12
13
14
# File 'lib/display.rb', line 12

def format
  @format
end

Instance Method Details

#display_resultsObject

print the contents of the FileHashResults object standard out in the format specified. Default is csv



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/display.rb', line 26

def display_results()

case @format
  when "csv"
      display_results_csv
  when "html"
      display_results_html
  when "json"
      display_results_json
    else
      display_results_std
    end
end

#display_results_csvObject

Prints the results to standard out in the csv format specified.



49
50
51
52
53
54
# File 'lib/display.rb', line 49

def display_results_csv
    puts Mustache.render(CsvTemplate,  :filedetails => @file_data[0]);
    if(@displayerrors)
      puts Mustache.render(CsvTemplate,  :filedetails => @error_data[0]);
    end
end

#display_results_htmlObject

Prints the results to standard out in the csv format specified.



57
58
59
60
61
62
# File 'lib/display.rb', line 57

def display_results_html
puts Mustache.render(HtmlTemplate,  :filedetails => @file_data[0]);
  if(@displayerrors)
    puts Mustache.render(HtmlTemplate,  :filedetails => @error_data[0]);
  end
end

#display_results_jsonObject

Prints the results to standard out in the csv format specified.



65
66
67
68
69
70
# File 'lib/display.rb', line 65

def display_results_json
  puts JSON.pretty_generate(@file_data) 
  if(@displayerrors)
    puts JSON.pretty_generate(@error_data) 
  end
end

#display_results_stdObject

Prints the results to standard out in the csv format specified.



41
42
43
44
45
46
# File 'lib/display.rb', line 41

def display_results_std
  puts Mustache.render(StandardTemplate,  :filedetails => @file_data[0]);
  if(@displayerrors)
    puts Mustache.render(StandardTemplate,  :errordetails => @error_data[0]);
  end
end