Class: JsonChecker::HTMLOutput

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_comparation_item(title, json) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/json_checker/html_output.rb', line 22

def self.add_comparation_item(title, json)

  if title.nil? || json.nil?
    return
  end

  item = "<h2>#{title}</h2>" + "<div class=\"diff\">" + json + "</div>"
  HTMLOutput.add_item(item)
end

.add_item(item) ⇒ Object



43
44
45
46
47
48
# File 'lib/json_checker/html_output.rb', line 43

def self.add_item(item)
  if @reportItems.nil?
    @reportItems = Array.new()
  end
  @reportItems << item
end

.add_validation_item(title, values) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/json_checker/html_output.rb', line 4

def self.add_validation_item(title, values)

  if title.nil? || values.nil? || !values.is_a?(Array)
    return
  end

  item = "<h2>#{title}</h2>"
  item << "<div class=\"validation\" style=\"overflow-x:auto;\">
  <table><tr><th>Status</th><th>Key</th><th>Expected</th><th>Value</th></tr>"

  values.each do |value|
    item << value
  end

  item << "</table></div>"
  HTMLOutput.add_item(item)
end

.generate_outputObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/json_checker/html_output.rb', line 32

def self.generate_output()
  htmlOutput = HTMLOutput.new()
  output = "<html>" + htmlOutput.add_style() + "<body>"
  @reportItems.each do |item| 
    output << item
  end
  output << "</body></html>"

  htmlOutput.save_to_file(output)
end

Instance Method Details

#add_styleObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/json_checker/html_output.rb', line 50

def add_style()
  return "<style>  
    .addition { background: #eaffea; }
    .remotion { background: #ffecec; }
    .diff { outline: 1px solid #eff0d6; margin: 5px; padding-top: 5px; padding-bottom: 5px; }
    .validation { margin: 5px; }
    body { font-family: monospace; }
    table { border-collapse: collapse; width: 100%; }
    td { border: 1px solid #eff0d6; }
    th { background-color: #4CAF50; color: white; border: 1px solid #4CAF50; }
    th, td { padding: 5px; text-align: left; }
    tr:hover { background-color: #f5f5f5 }
    p { margin-top: 0em; margin-bottom: 0em; white-space: pre; padding : 3; color: #3e3333 }
  </style>"
end

#save_to_file(report) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/json_checker/html_output.rb', line 66

def save_to_file(report)
  if report.nil?
    puts "[ERROR] Invalid report"
  else
    File.write("output.html", report)
  end
end