Class: ChupaText::VirtualContent

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

Constant Summary collapse

KILO_BYTE =
1024
BUFFER_SIZE =
64 * KILO_BYTE

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, original_path = nil) ⇒ VirtualContent

Returns a new instance of VirtualContent.



26
27
28
29
30
31
32
33
# File 'lib/chupa-text/virtual-content.rb', line 26

def initialize(input, original_path=nil)
  @file = nil
  @base_name = compute_base_name(original_path)
  @body = nil
  setup_file do |file|
    @size = IO.copy_stream(input, file)
  end
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



25
26
27
# File 'lib/chupa-text/virtual-content.rb', line 25

def size
  @size
end

Instance Method Details

#bodyObject



39
40
41
# File 'lib/chupa-text/virtual-content.rb', line 39

def body
  @body ||= open {|file| file.read}
end

#open(&block) ⇒ Object



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

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

#pathObject



43
44
45
# File 'lib/chupa-text/virtual-content.rb', line 43

def path
  @path
end