Class: FileComposer::Documents::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/file_composer/documents/text.rb

Overview

Writes basic, static text file

Instance Attribute Summary collapse

Attributes inherited from Base

#filename

Instance Method Summary collapse

Constructor Details

#initialize(filename:, data: '') ⇒ Text

Returns a new instance of Text.



18
19
20
21
22
# File 'lib/file_composer/documents/text.rb', line 18

def initialize(filename:, data: '')
  super(filename: filename)

  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/file_composer/documents/text.rb', line 16

def data
  @data
end

Instance Method Details

#write!(temp_root = '', store = Stores::Null.new) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/file_composer/documents/text.rb', line 24

def write!(temp_root = '', store = Stores::Null.new)
  temp_filename = make_temp_filename(temp_root)

  time_in_seconds = Benchmark.measure do
    # First, write out the temporary file
    FileUtils.mkdir_p(File.dirname(temp_filename))
    IO.write(temp_filename, data)
  end.real

  # Then copy the file to permanent store
  physical_filename = store.move!(temp_filename)
  file_result       = FileResult.new(filename, physical_filename)

  Result.new(file_result, time_in_seconds)
end