Class: Montage::Source
- Inherits:
-
Object
- Object
- Montage::Source
- Defined in:
- lib/montage/source.rb
Overview
Represents a single source file used in a sprite.
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#digest ⇒ String
Returns a digest which represents the sprite name and file contents.
-
#image ⇒ Magick::Image
Returns the RMagick image instance representing the source.
-
#initialize(path) ⇒ Source
constructor
Creates a new Source instance.
-
#inspect ⇒ Object
:nodoc.
Constructor Details
#initialize(path) ⇒ Source
Creates a new Source instance.
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
#name ⇒ Object (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 |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/montage/source.rb', line 6 def path @path end |
Instance Method Details
#digest ⇒ String
Returns a digest which represents the sprite name and file contents.
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 |
#image ⇒ Magick::Image
Returns the RMagick image instance representing the source.
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 |
#inspect ⇒ Object
:nodoc
19 20 21 |
# File 'lib/montage/source.rb', line 19 def inspect # :nodoc "#<Montage::Source #{@name}>" end |