Class: Vivlio::PDF::LocalFile

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio/pdf/local_file.rb

Overview

A file on disk the browser will be pointed at: a path that exists, and the file:// URL naming it.

Everything the viewer loads -- the document, its stylesheets, the viewer's own index.html -- is one of these. kind only names the thing in the error raised when it is missing.

Direct Known Subclasses

Source

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, kind: 'file') ⇒ LocalFile

Returns a new instance of LocalFile.

Raises:



20
21
22
23
24
25
26
# File 'lib/vivlio/pdf/local_file.rb', line 20

def initialize(path, kind: 'file')
  @path = File.expand_path(path.to_s)
  raise Error, "#{kind} not found: #{@path}" unless File.exist?(@path)

  @url = file_url(@path)
  freeze
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



14
15
16
# File 'lib/vivlio/pdf/local_file.rb', line 14

def path
  @path
end

#urlObject (readonly)

Returns the value of attribute url.



14
15
16
# File 'lib/vivlio/pdf/local_file.rb', line 14

def url
  @url
end

Class Method Details

.coerce(value) ⇒ Object



16
17
18
# File 'lib/vivlio/pdf/local_file.rb', line 16

def self.coerce(value)
  value.is_a?(self) ? value : new(value)
end

Instance Method Details

#to_sObject



28
29
30
# File 'lib/vivlio/pdf/local_file.rb', line 28

def to_s
  path
end