Class: TestFile::Builder

Inherits:
Struct
  • Object
show all
Defined in:
lib/test_file/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



22
23
24
# File 'lib/test_file/builder.rb', line 22

def name
  @name
end

Instance Method Details

#as_pdfObject



29
30
31
# File 'lib/test_file/builder.rb', line 29

def as_pdf
  PDFBuilder.new(self)
end

#deleteObject



41
42
43
# File 'lib/test_file/builder.rb', line 41

def delete
  File.delete(path) if exist?
end

#exist?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/test_file/builder.rb', line 45

def exist?
  File.exists?(path)
end

#include?(content) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/test_file/builder.rb', line 49

def include?(content)
  reader.read.include?(content)
end

#pathObject



53
54
55
# File 'lib/test_file/builder.rb', line 53

def path
  name
end

#readerObject



37
38
39
# File 'lib/test_file/builder.rb', line 37

def reader
  @reader ||= File.new(path, 'r')
end

#to_sObject Also known as: inspect



57
58
59
# File 'lib/test_file/builder.rb', line 57

def to_s
  "TestFile #{path}"
end

#with_content(content) ⇒ Object



23
24
25
26
27
# File 'lib/test_file/builder.rb', line 23

def with_content(content)
  writer.write(content)
  writer.flush
  self
end

#writerObject



33
34
35
# File 'lib/test_file/builder.rb', line 33

def writer
  @writer ||= File.new(path, 'w+')
end