Class: PDFKit::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfkit/source.rb

Constant Summary collapse

SOURCE_FROM_STDIN =
'-'

Instance Method Summary collapse

Constructor Details

#initialize(url_file_or_html) ⇒ Source

Returns a new instance of Source.



10
11
12
13
14
# File 'lib/pdfkit/source.rb', line 10

def initialize(url_file_or_html)
  @source = url_file_or_html
  # @source is assumed to be modifiable, so make sure it is.
  @source = @source.dup if @source.is_a?(String) && @source.frozen?
end

Instance Method Details

#file?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/pdfkit/source.rb', line 20

def file?
  @is_file ||= @source.kind_of?(File) || @source.kind_of?(Tempfile)
end

#html?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/pdfkit/source.rb', line 24

def html?
  @is_html ||= !(url? || file?)
end

#to_input_for_commandObject



28
29
30
31
32
33
34
35
36
# File 'lib/pdfkit/source.rb', line 28

def to_input_for_command
  if file?
    @source.path
  elsif url?
    escaped_url
  else
    SOURCE_FROM_STDIN
  end
end

#to_sObject



38
39
40
# File 'lib/pdfkit/source.rb', line 38

def to_s
  file? ? @source.path : @source
end

#url?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/pdfkit/source.rb', line 16

def url?
  @is_url ||= @source.is_a?(String) && @source.match(/\Ahttp/)
end