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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/chupa-text/virtual-content.rb', line 27

def initialize(input, original_path=nil)
  @file = nil
  if original_path.is_a?(String)
    if original_path.empty?
      original_path = nil
    else
      original_path = Pathname.new(original_path)
    end
  end
  @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.



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

def size
  @size
end

Instance Method Details

#bodyObject



47
48
49
# File 'lib/chupa-text/virtual-content.rb', line 47

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

#open(&block) ⇒ Object



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

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

#pathObject



51
52
53
# File 'lib/chupa-text/virtual-content.rb', line 51

def path
  @path
end