Class: PhantomPDF::Source

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

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ Source

Returns a new instance of Source.

Raises:



5
6
7
8
9
# File 'lib/phantompdf/source.rb', line 5

def initialize(src)
  @source = src

  raise SourceTypeError.new('Unsupported source type.') unless valid?
end

Instance Method Details

#file?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/phantompdf/source.rb', line 17

def file?
  !url? && (@source.kind_of?(File) || File.exists?(@source))
end

#html?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/phantompdf/source.rb', line 21

def html?
  !(url? || file?)
end

#to_sObject



29
30
31
32
33
# File 'lib/phantompdf/source.rb', line 29

def to_s
  return @source if url? || html?

  @source.kind_of?(File) ? @source.path : @source
end

#url?Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/phantompdf/source.rb', line 11

def url?
  !URI.parse(@source).scheme.nil?
rescue
  false
end

#valid?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/phantompdf/source.rb', line 25

def valid?
  url? || file? || html?
end