Class: PhantomPDF::Source
- Inherits:
-
Object
- Object
- PhantomPDF::Source
- Defined in:
- lib/phantompdf/source.rb
Instance Method Summary collapse
- #file? ⇒ Boolean
- #html? ⇒ Boolean
-
#initialize(src) ⇒ Source
constructor
A new instance of Source.
- #to_s ⇒ Object
- #url? ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(src) ⇒ Source
Returns a new instance of Source.
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
17 18 19 |
# File 'lib/phantompdf/source.rb', line 17 def file? !url? && (@source.kind_of?(File) || File.exists?(@source)) end |
#html? ⇒ Boolean
21 22 23 |
# File 'lib/phantompdf/source.rb', line 21 def html? !(url? || file?) end |
#to_s ⇒ Object
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
11 12 13 14 15 |
# File 'lib/phantompdf/source.rb', line 11 def url? !URI.parse(@source).scheme.nil? rescue false end |
#valid? ⇒ Boolean
25 26 27 |
# File 'lib/phantompdf/source.rb', line 25 def valid? url? || file? || html? end |