Module: Coradoc::AsciiDoc::Model::Resolvable

Included in:
Include
Defined in:
lib/coradoc/asciidoc/model/resolvable.rb

Overview

Module for nodes that reference external resources.

Any model element that references an external file or resource should include this module to provide a unified interface for resolution operations.

Examples:

Implementing Resolvable in a class

class Include < Base
  include Resolvable

  def reference_path
    path
  end

  def reference_type
    :include
  end
end

Instance Method Summary collapse

Instance Method Details

#local_reference?Boolean

Checks if the reference is to a local file.

Returns:

  • (Boolean)

    true if the reference is a local file path



54
55
56
57
58
59
60
# File 'lib/coradoc/asciidoc/model/resolvable.rb', line 54

def local_reference?
  path = reference_path
  return false if path.nil?

  # Not a URL if it doesn't start with a scheme
  !path.match?(%r{^[a-z][a-z0-9+.-]*://}i)
end

#reference_optionsHash

Returns additional options for reference resolution.

Returns:

  • (Hash)

    options for resolution (e.g., leveloffset, lines, tags)



47
48
49
# File 'lib/coradoc/asciidoc/model/resolvable.rb', line 47

def reference_options
  {}
end

#reference_pathString

Returns the path to the external resource.

Returns:

  • (String)

    the path or URL to the external resource

Raises:

  • (NotImplementedError)

    if not implemented by including class



30
31
32
33
# File 'lib/coradoc/asciidoc/model/resolvable.rb', line 30

def reference_path
  raise NotImplementedError,
        "#{self.class} must implement #reference_path"
end

#reference_typeSymbol

Returns the type of reference.

Returns:

  • (Symbol)

    the reference type (:include, :image, :video, :audio, :link)

Raises:

  • (NotImplementedError)

    if not implemented by including class



39
40
41
42
# File 'lib/coradoc/asciidoc/model/resolvable.rb', line 39

def reference_type
  raise NotImplementedError,
        "#{self.class} must implement #reference_type"
end

#remote_reference?Boolean

Checks if the reference is to a remote URL.

Returns:

  • (Boolean)

    true if the reference is a URL



65
66
67
# File 'lib/coradoc/asciidoc/model/resolvable.rb', line 65

def remote_reference?
  !local_reference?
end