Class: Picturama::Picture

Inherits:
File
  • Object
show all
Defined in:
lib/picturama/picture.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Picture

Returns a new instance of Picture.



8
9
10
11
12
13
# File 'lib/picturama/picture.rb', line 8

def initialize(args)
  super
  @thumbnail = "#{File.dirname(path)}/thumbnails/#{Picturama::config['thumbnail_prefix']}#{basename}"
  @resized = "#{File.dirname(path)}/resized/resized_#{basename}"
  @metainfo = "#{File.dirname(path)}/resized/resized_#{basename}.info"
end

Instance Attribute Details

#metainfo ⇒ Object

Returns the value of attribute metainfo.



6
7
8
# File 'lib/picturama/picture.rb', line 6

def metainfo
  @metainfo
end

#resized ⇒ Object

Returns the value of attribute resized.



6
7
8
# File 'lib/picturama/picture.rb', line 6

def resized
  @resized
end

#thumbnail ⇒ Object

Returns the value of attribute thumbnail.



6
7
8
# File 'lib/picturama/picture.rb', line 6

def thumbnail
  @thumbnail
end

Instance Method Details

#basename ⇒ Object



15
16
17
# File 'lib/picturama/picture.rb', line 15

def basename
  File.basename(path)
end

#has_resized? ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/picturama/picture.rb', line 23

def has_resized?
  File.exists?(@resized)
end

#has_thumbnail? ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/picturama/picture.rb', line 27

def has_thumbnail?
  File.exists?(@thumbnail) && File.size(@thumbnail) < size
end

#info ⇒ Object



19
20
21
# File 'lib/picturama/picture.rb', line 19

def info
  File.read(@metainfo) if File.exists?(@metainfo)
end

#remove_assoc ⇒ Object



31
32
33
34
# File 'lib/picturama/picture.rb', line 31

def remove_assoc
  File.delete(@thumbnail) if has_thumbnail?
  File.delete(@resized) if has_resized?
end

#type ⇒ Object



36
37
38
# File 'lib/picturama/picture.rb', line 36

def type
  File.extname(path).split('.').last
end