Class: Vedeu::Renderers::File

Inherits:
Object
  • Object
show all
Includes:
Vedeu::RendererOptions
Defined in:
lib/vedeu/output/renderers/file.rb

Overview

Writes the given output to a file.

Direct Known Subclasses

HTML, JSON

Instance Method Summary collapse

Methods included from Vedeu::RendererOptions

#options

Constructor Details

#initialize(options = {}) ⇒ Vedeu::Renderers::File

Returns a new instance of Vedeu::Renderers::File.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • filename (String)

    Provide a filename for the output. Defaults to ‘out’.

  • timestamp (Boolean)

    Append a timestamp to the filename.

  • write_file (Boolean)

    Whether to write the file to the given filename.



20
21
22
# File 'lib/vedeu/output/renderers/file.rb', line 20

def initialize(options = {})
  @options = options || {}
end

Instance Method Details

#defaultsHash (private)

Returns the default options/attributes for this class.

Returns:

  • (Hash)


52
53
54
55
56
57
58
# File 'lib/vedeu/output/renderers/file.rb', line 52

def defaults
  {
    filename:   'out',
    timestamp:  false,
    write_file: true,
  }
end

#filenameString (private)

Returns:

  • (String)


35
36
37
# File 'lib/vedeu/output/renderers/file.rb', line 35

def filename
  options[:filename] + "_#{timestamp}"
end

#render(output) ⇒ String

Parameters:

Returns:

  • (String)


26
27
28
29
30
# File 'lib/vedeu/output/renderers/file.rb', line 26

def render(output)
  ::File.write(filename, output) if write_file?

  output
end

#timestampFloat (private)

Returns:

  • (Float)


40
41
42
# File 'lib/vedeu/output/renderers/file.rb', line 40

def timestamp
  Time.now.to_f if options[:timestamp]
end

#write_file?Boolean (private)

Returns:

  • (Boolean)


45
46
47
# File 'lib/vedeu/output/renderers/file.rb', line 45

def write_file?
  options[:write_file]
end