Class: ChupaText::FileContent

Inherits:
Object
  • Object
show all
Defined in:
lib/chupa-text/file-content.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileContent

Returns a new instance of FileContent.



22
23
24
25
# File 'lib/chupa-text/file-content.rb', line 22

def initialize(path)
  @path = path
  @size = File.size(@path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



20
21
22
# File 'lib/chupa-text/file-content.rb', line 20

def path
  @path
end

#sizeObject (readonly)

Returns the value of attribute size.



19
20
21
# File 'lib/chupa-text/file-content.rb', line 19

def size
  @size
end

Instance Method Details

#bodyObject



34
35
36
37
38
# File 'lib/chupa-text/file-content.rb', line 34

def body
  open do |file|
    file.read
  end
end

#open(&block) ⇒ Object



27
28
29
# File 'lib/chupa-text/file-content.rb', line 27

def open(&block)
  File.open(@path, "rb", &block)
end

#peek_body(size) ⇒ Object



40
41
42
43
44
# File 'lib/chupa-text/file-content.rb', line 40

def peek_body(size)
  open do |file|
    file.read(size)
  end
end

#releaseObject



31
32
# File 'lib/chupa-text/file-content.rb', line 31

def release
end