Class: Vedeu::Renderers::File

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

Overview

Converts a grid of Char objects into a stream of escape sequences and content suitable for a terminal, and writes them to a file in the /tmp directory.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

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

Parameters:

  • output (Array<Array<Vedeu::Char>>)
  • options (Hash) (defaults to: {})


22
23
24
25
# File 'lib/vedeu/output/renderers/file.rb', line 22

def initialize(output, options = {})
  @output  = output
  @options = options
end

Instance Attribute Details

#outputArray<Array<Vedeu::Char>> (readonly, protected)

Returns:



38
39
40
# File 'lib/vedeu/output/renderers/file.rb', line 38

def output
  @output
end

Class Method Details

.render(output, options = {}) ⇒ String

Parameters:

  • output (Array<Array<Vedeu::Char>>)
  • options (Hash) (defaults to: {})

Returns:

  • (String)


13
14
15
# File 'lib/vedeu/output/renderers/file.rb', line 13

def self.render(output, options = {})
  new(output, options).render
end

Instance Method Details

#defaultsHash (private)

Returns:

  • (Hash)


81
82
83
84
85
# File 'lib/vedeu/output/renderers/file.rb', line 81

def defaults
  {
    timestamp: false,
  }
end

#filenameString (private)

Returns:

  • (String)


48
49
50
51
52
53
54
55
56
# File 'lib/vedeu/output/renderers/file.rb', line 48

def filename
  if timestamp?
    "out_#{timestamp}"

  else
    'out'

  end
end

#optionsHash (private)

Returns:

  • (Hash)


76
77
78
# File 'lib/vedeu/output/renderers/file.rb', line 76

def options
  defaults.merge!(@options)
end

#parsedString (private)

Returns:

  • (String)


59
60
61
# File 'lib/vedeu/output/renderers/file.rb', line 59

def parsed
  @parsed ||= Vedeu::Compressor.new(output).render
end

#pathString (private)

Returns:

  • (String)


43
44
45
# File 'lib/vedeu/output/renderers/file.rb', line 43

def path
  "/tmp/#{filename}"
end

#renderString

Returns:

  • (String)


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

def render
  ::File.open(path, 'w') { |f| f.write(parsed) }

  parsed
end

#timestampFloat (private)

Returns:

  • (Float)


64
65
66
# File 'lib/vedeu/output/renderers/file.rb', line 64

def timestamp
  @timestamp ||= Time.now.to_f
end

#timestamp?Boolean (private)

Returns:

  • (Boolean)


69
70
71
72
73
# File 'lib/vedeu/output/renderers/file.rb', line 69

def timestamp?
  return true if options[:timestamp]

  false
end