Class: Montage::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/montage/source.rb

Overview

Represents a single source file used in a sprite.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Source

Creates a new Source instance.

Parameters:

  • path (Pathname)

    The path the the source image.



14
15
16
17
# File 'lib/montage/source.rb', line 14

def initialize(path)
  @path = Pathname.new(path)
  @name = @path.basename.to_s.chomp(@path.extname.to_s)
end

Instance Attribute Details

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



6
7
8
# File 'lib/montage/source.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/montage/source.rb', line 6

def path
  @path
end

Instance Method Details

#digestString

Returns a digest which represents the sprite name and file contents.

Returns:

Raises:



38
39
40
41
42
43
# File 'lib/montage/source.rb', line 38

def digest
  raise MissingSource, "Couldn't find the source file `#{@path}'" \
    unless @path.file?

  Digest::SHA256.hexdigest(@name + Digest::SHA256.file(@path).to_s)
end

#imageMagick::Image

Returns the RMagick image instance representing the source.

Returns:

  • (Magick::Image)

Raises:



27
28
29
30
31
32
# File 'lib/montage/source.rb', line 27

def image
  raise MissingSource, "Couldn't find the source file `#{@path}'" \
    unless @path.file?

  @image ||= Magick::Image.read(@path).first
end

#inspectObject

:nodoc



19
20
21
# File 'lib/montage/source.rb', line 19

def inspect # :nodoc
  "#<Montage::Source #{@name}>"
end