Class: Prawn::Attachment::Filespec

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/attachment/filespec.rb

Overview

FileSpec corresponds to the PDF file specification object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ Filespec

Returns a new instance of Filespec.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/prawn/attachment/filespec.rb', line 11

def initialize(file, options = {})
  hexdigest = Digest.hexencode(file.data[:Params][:CheckSum])
  name = options[:name] || hexdigest

  @file_name = PDF::Core::LiteralString.new(name)

  if options[:description]
    desc_str = options[:description].to_s
    @description = PDF::Core::LiteralString.new(desc_str)
  end

  @hidden = options[:hidden]
  @file = file
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



9
10
11
# File 'lib/prawn/attachment/filespec.rb', line 9

def file_name
  @file_name
end

Instance Method Details

#build_pdf_object(document) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/prawn/attachment/filespec.rb', line 30

def build_pdf_object(document)
  obj = document.ref!(
    Type: :Filespec,
    F: file_name,
    EF: { F: file, UF: file },
    UF: file_name
  )

  obj.data[:Desc] = description if description
  obj
end

#hidden?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/prawn/attachment/filespec.rb', line 26

def hidden?
  @hidden
end