Class: Vedeu::Renderers::File
- Inherits:
-
Object
- Object
- Vedeu::Renderers::File
- Includes:
- Options
- Defined in:
- lib/vedeu/output/renderers/file.rb
Overview
Writes the given output to a file.
Instance Attribute Summary collapse
-
#options ⇒ Hash<Symbol => void>
included
from Options
private
Combines the options provided at instantiation with the default values.
Instance Method Summary collapse
- #compress? ⇒ Boolean included from Options
-
#defaults ⇒ Hash
private
Returns the default options/attributes for this class.
-
#filename ⇒ String
private
Return the filename given in the options, (or use the default), and append a timestamp if the :timestamp option was set to true.
-
#initialize(options = {}) ⇒ Vedeu::Renderers::File
constructor
Returns a new instance of Vedeu::Renderers::File.
-
#out(output) ⇒ String
private
Compresses the output depending on configuration.
-
#render(output = '', opts = {}) ⇒ String
(also: #clear)
Render the output (either content or clearing) to a file.
-
#timestamp ⇒ Float
private
Return a timestamp for use as part of the filename if the :timestamp option was set to true, otherwise an empty string.
-
#write_file? ⇒ Boolean
private
Returns a boolean indicating whether a file should be written.
Constructor Details
#initialize(options = {}) ⇒ Vedeu::Renderers::File
Returns a new instance of Vedeu::Renderers::File.
21 22 23 |
# File 'lib/vedeu/output/renderers/file.rb', line 21 def initialize( = {}) @options = || {} end |
Instance Attribute Details
#options ⇒ Hash<Symbol => void> (private) Originally defined in module Options
Combines the options provided at instantiation with the default values.
Instance Method Details
#compress? ⇒ Boolean Originally defined in module Options
#defaults ⇒ Hash (private)
Returns the default options/attributes for this class.
88 89 90 91 92 93 94 95 |
# File 'lib/vedeu/output/renderers/file.rb', line 88 def defaults { compression: Vedeu::Configuration.compression?, filename: 'out', timestamp: false, write_file: true, } end |
#filename ⇒ String (private)
Return the filename given in the options, (or use the default), and append a timestamp if the :timestamp option was set to true.
60 61 62 |
# File 'lib/vedeu/output/renderers/file.rb', line 60 def filename [:filename] + end |
#out(output) ⇒ String (private)
Compresses the output depending on configuration.
45 46 47 48 49 50 51 52 53 |
# File 'lib/vedeu/output/renderers/file.rb', line 45 def out(output) if compress? Vedeu::Output::Compressor.render(output, ) else output end end |
#render(output = '', opts = {}) ⇒ String Also known as: clear
Render the output (either content or clearing) to a file.
30 31 32 33 34 35 36 |
# File 'lib/vedeu/output/renderers/file.rb', line 30 def render(output = '', opts = {}) @options = .merge!(opts) ::File.write(filename, out(output)) if write_file? out(output) end |
#timestamp ⇒ Float (private)
Return a timestamp for use as part of the filename if the :timestamp option was set to true, otherwise an empty string.
68 69 70 71 72 73 74 75 76 |
# File 'lib/vedeu/output/renderers/file.rb', line 68 def if [:timestamp] "_#{Vedeu.clock_time}".freeze else ''.freeze end end |
#write_file? ⇒ Boolean (private)
Returns a boolean indicating whether a file should be written.
81 82 83 |
# File 'lib/vedeu/output/renderers/file.rb', line 81 def write_file? [:write_file] end |