Class: RGallery::Photo

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-gallery/rgallery/photo.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, options = {}) ⇒ Photo

Returns a new instance of Photo.



5
6
7
8
9
10
# File 'lib/rails-gallery/rgallery/photo.rb', line 5

def initialize obj, options = {}
  @obj = obj
  self.sources = options.delete :sources
  @sizing = options.delete :sizing
  @options = options
end

Class Attribute Details

.extensionObject



76
77
78
# File 'lib/rails-gallery/rgallery/photo.rb', line 76

def extension
  @extension ||= :png
end

Instance Attribute Details

#objObject (readonly) Also known as: id

Returns the value of attribute obj.



3
4
5
# File 'lib/rails-gallery/rgallery/photo.rb', line 3

def obj
  @obj
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/rails-gallery/rgallery/photo.rb', line 3

def options
  @options
end

#sizingObject (readonly)

Returns the value of attribute sizing.



3
4
5
# File 'lib/rails-gallery/rgallery/photo.rb', line 3

def sizing
  @sizing
end

#sourcesObject

Returns the value of attribute sources.



3
4
5
# File 'lib/rails-gallery/rgallery/photo.rb', line 3

def sources
  @sources
end

Instance Method Details

#altObject



61
62
63
# File 'lib/rails-gallery/rgallery/photo.rb', line 61

def alt
  'no alt'
end

#descriptionObject



65
66
67
# File 'lib/rails-gallery/rgallery/photo.rb', line 65

def description
  'no description'
end

#extensionObject



69
70
71
# File 'lib/rails-gallery/rgallery/photo.rb', line 69

def extension
  options[:extension] || self.class.extension
end

#file_pathObject



45
46
47
# File 'lib/rails-gallery/rgallery/photo.rb', line 45

def file_path
  "#{filename}.#{extension}"
end

#filenameObject



41
42
43
# File 'lib/rails-gallery/rgallery/photo.rb', line 41

def filename
  id
end

#pathObject



49
50
51
# File 'lib/rails-gallery/rgallery/photo.rb', line 49

def path
  file_path
end

#source_photosObject

A photo can contain a source set of other photos!



28
29
30
31
32
33
# File 'lib/rails-gallery/rgallery/photo.rb', line 28

def source_photos
  return [] unless sources.kind_of? Array
  @source_photos ||= sources.map do |source| 
    RGallery::Photo.new source.src, options.merge(:sizing => source.sizing)
  end
end

#srcsetObject

map [‘banner-HD.jpeg’, sizing: ‘2x’, ‘banner-phone.jpeg’, sizing: ‘100w’] into -> “banner-HD.jpeg 2x, banner-phone.jpeg 100w



16
17
18
19
20
21
# File 'lib/rails-gallery/rgallery/photo.rb', line 16

def srcset
  return '' unless sources_photos.kind_of? Array
  @srcset ||= source_photos.inject([]) do |res, photo| 
    res << [photo.id, photo.sizing].join(' ')
  end.join(',')
end

#srcset?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rails-gallery/rgallery/photo.rb', line 23

def srcset?
  !srcset.blank?
end

#thumbObject



53
54
55
# File 'lib/rails-gallery/rgallery/photo.rb', line 53

def thumb
  path
end

#titleObject



57
58
59
# File 'lib/rails-gallery/rgallery/photo.rb', line 57

def title
  'no title'
end