lib/request_log_analyzer/output/html.rb in request-log-analyzer-1.13.1 vs lib/request_log_analyzer/output/html.rb in request-log-analyzer-1.13.3

- old
+ new

@@ -1,10 +1,8 @@ module RequestLogAnalyzer::Output - # HTML Output class. Generated a HTML-formatted report, including CSS. class HTML < Base - # def initialize(io, options = {}) # super(io, options) # end def colorize(text, *style) @@ -18,11 +16,11 @@ # Print a string to the io object. def print(str) @io << str end - alias :<< :print + alias_method :<<, :print # Put a string with newline def puts(str = '') @io << str << "<br/>\n" end @@ -32,30 +30,30 @@ @io.puts(tag(:h2, title)) end # Render a single line # <tt>*font</tt> The font. - def line(*font) + def line(*_font) @io.puts(tag(:hr)) end # Write a link # <tt>text</tt> The text in the link # <tt>url</tt> The url to link to. def link(text, url = nil) url = text if url.nil? - tag(:a, text, :href => url) + tag(:a, text, href: url) end # Generate a report table in HTML and push it into the output object. # <tt>*colums<tt> Columns hash # <tt>&block</tt>: A block yeilding the rows. - def table(*columns, &block) - rows = Array.new + def table(*columns, &_block) + rows = [] yield(rows) - @io << tag(:table, {:class => 'rla-report-table', :cellspacing => 0}) do |content| + @io << tag(:table, class: 'rla-report-table', cellspacing: 0) do |content| if table_has_header?(columns) content << tag(:tr) do columns.map { |col| tag(:th, col[:title]) }.join("\n") end end @@ -63,25 +61,24 @@ odd = false rows.each do |row| odd = !odd content << tag(:tr) do if odd - row.map { |cell| tag(:td, cell, :class => 'alt') }.join("\n") + row.map { |cell| tag(:td, cell, class: 'alt') }.join("\n") else row.map { |cell| tag(:td, cell) }.join("\n") end end end end - end # Genrate HTML header and associated stylesheet def header @io.content_type = content_type if @io.respond_to?(:content_type) - @io << "<html>" + @io << '<html>' @io << tag(:head) do |headers| headers << tag(:title, 'Request-log-analyzer report') headers << tag(:style, ' body { font: normal 11px auto "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; @@ -109,11 +106,11 @@ padding-bottom:10px; } caption { padding: 0 0 5px 0; - width: 700px; + width: 700px; font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif; text-align: right; } th { @@ -140,11 +137,11 @@ td.alt { background: #F5FAFA; color: #797268; } - ', :type => "text/css") + ', type: 'text/css') end @io << '<body>' @io << tag(:h1, 'Request-log-analyzer summary report') @io << tag(:p, "Version #{RequestLogAnalyzer::VERSION} - written by Willem van Bergen and Bart ten Brinke") end @@ -174,10 +171,10 @@ attributes = attributes.nil? ? '' : ' ' + attributes.map { |(key, value)| "#{key}=\"#{value}\"" }.join(' ') if content.nil? "<#{tag}#{attributes} />" else if content.class == Float - "<#{tag}#{attributes}><div class='color_bar' style=\"width:#{(content*200).floor}px;\"/></#{tag}>" + "<#{tag}#{attributes}><div class='color_bar' style=\"width:#{(content * 200).floor}px;\"/></#{tag}>" else "<#{tag}#{attributes}>#{content}</#{tag}>" end end end