Class: ChupaText::FileContent
- Inherits:
-
Object
- Object
- ChupaText::FileContent
- Defined in:
- lib/chupa-text/file-content.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#body ⇒ Object
-
#initialize(path) ⇒ FileContent
constructor
A new instance of FileContent.
-
#open(&block) ⇒ Object
-
#peek_body(size) ⇒ Object
-
#release ⇒ Object
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
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/chupa-text/file-content.rb', line 20 def path @path end |
#size ⇒ Object (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
#body ⇒ Object
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 |
#release ⇒ Object
31 32 |
# File 'lib/chupa-text/file-content.rb', line 31 def release end |