Class: Peregrin::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/peregrin/resource.rb

Overview

Any file that is a part of the book but not one of its linear sections (ie, Components) is a Resource.

Resources can potentially be quite large, so as far as possible we don't store their contents in memory.

Direct Known Subclasses

Component

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src, media_type = nil, attributes = {}) ⇒ Resource

Returns a new instance of Resource



12
13
14
15
16
17
# File 'lib/peregrin/resource.rb', line 12

def initialize(src, media_type = nil, attributes = {})
  @src = src
  @media_type = media_type || MIME::Types.of(File.basename(@src))
  @media_type = @media_type.first  if @media_type.kind_of?(Array)
  @attributes = attributes
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes



9
10
11
# File 'lib/peregrin/resource.rb', line 9

def attributes
  @attributes
end

#media_typeObject



20
21
22
# File 'lib/peregrin/resource.rb', line 20

def media_type
  @media_type ? @media_type.to_s : nil
end

#srcObject

Returns the value of attribute src



9
10
11
# File 'lib/peregrin/resource.rb', line 9

def src
  @src
end