Class: Htmlout
- Inherits:
-
Object
- Object
- Htmlout
- Defined in:
- lib/newsman/html_output.rb
Overview
This class represents a report output in HTML format.
Constant Summary collapse
- TEMPLATE =
<<~HTML <head> <title><%= title %></title> </head> <body> <h1><%= title %></h1> <%= body %> </body> HTML
Instance Method Summary collapse
- #filename(reporter, model) ⇒ Object
-
#initialize(root = '.') ⇒ Htmlout
constructor
A new instance of Htmlout.
-
#print(report, reporter, model) ⇒ Object
rubocop:disable Metrics/AbcSize.
-
#title(reporter) ⇒ Object
rubocop:enable Metrics/AbcSize.
- #to_html(report) ⇒ Object
Constructor Details
Instance Method Details
#filename(reporter, model) ⇒ Object
61 62 63 64 65 |
# File 'lib/newsman/html_output.rb', line 61 def filename(reporter, model) date = Time.new.strftime('%d.%m.%Y') model = model.gsub('.', '-') "#{date}.#{reporter}.#{model}.html" end |
#print(report, reporter, model) ⇒ Object
rubocop:disable Metrics/AbcSize
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/newsman/html_output.rb', line 44 def print(report, reporter, model) title = title(reporter) body = to_html(report) puts "Create a html file in a directory #{@root}" file = File.new(File.join(@root, filename(reporter, model)), 'w') puts "File #{file.path} was successfully created" file.puts Nokogiri::HTML(ERB.new(TEMPLATE).result(binding), &:noblanks).to_xhtml(indent: 2) puts "Report was successfully printed to a #{file.path}" file.close end |
#title(reporter) ⇒ Object
rubocop:enable Metrics/AbcSize
56 57 58 59 |
# File 'lib/newsman/html_output.rb', line 56 def title(reporter) date = Time.new.strftime('%d.%m.%Y') "#{reporter} #{date}" end |
#to_html(report) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/newsman/html_output.rb', line 67 def to_html(report) Redcarpet::Markdown.new( Redcarpet::Render::HTML.new(no_links: true, hard_wrap: true, prettify: true), autolink: true, tables: true ).render(report) end |