Class: PDFKit::Source
- Inherits:
-
Object
- Object
- PDFKit::Source
- Defined in:
- lib/pdfkit/source.rb
Constant Summary collapse
- SOURCE_FROM_STDIN =
'-'
Instance Method Summary collapse
- #file? ⇒ Boolean
- #html? ⇒ Boolean
-
#initialize(url_file_or_html) ⇒ Source
constructor
A new instance of Source.
- #to_input_for_command ⇒ Object
- #to_s ⇒ Object
- #url? ⇒ Boolean
Constructor Details
#initialize(url_file_or_html) ⇒ Source
Returns a new instance of Source.
7 8 9 |
# File 'lib/pdfkit/source.rb', line 7 def initialize(url_file_or_html) @source = url_file_or_html end |
Instance Method Details
#file? ⇒ Boolean
15 16 17 |
# File 'lib/pdfkit/source.rb', line 15 def file? @is_file ||= @source.kind_of?(File) || @source.kind_of?(Tempfile) end |
#html? ⇒ Boolean
19 20 21 |
# File 'lib/pdfkit/source.rb', line 19 def html? @is_html ||= !(url? || file?) end |
#to_input_for_command ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/pdfkit/source.rb', line 23 def to_input_for_command if file? @source.path elsif url? %{"#{shell_safe_url}"} else SOURCE_FROM_STDIN end end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/pdfkit/source.rb', line 33 def to_s file? ? @source.path : @source end |
#url? ⇒ Boolean
11 12 13 |
# File 'lib/pdfkit/source.rb', line 11 def url? @is_url ||= @source.is_a?(String) && @source.match(/\Ahttp/) end |