Class: Polites::Convert

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

Overview

Convert a Polites file to another format.

Instance Method Summary collapse

Constructor Details

#initialize(parser: Polites::Parser.new, formatter: Polites::HtmlFormatter.new) ⇒ Convert

Returns a new instance of Convert.

Parameters:



12
13
14
15
# File 'lib/polites/convert.rb', line 12

def initialize(parser: Polites::Parser.new, formatter: Polites::HtmlFormatter.new)
  @parser = parser
  @formatter = formatter
end

Instance Method Details

#call(filename) ⇒ String

Convert the contents of filename to HTML and return the result as a String.

Parameters:

  • filename (#to_s, #to_path)

Returns:

  • (String)


21
22
23
24
25
26
27
# File 'lib/polites/convert.rb', line 21

def call(filename)
  File.open(filename) do |f|
    f.content
     .then { |c| @parser.parse_sheet(c) }
     .then { |c| @formatter.call(c) }
  end
end