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(id, 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 id, options = {}
  @id = id
  self.sources = options.delete :sources
  @sizing = options.delete :sizing
  @options = options
end

Class Attribute Details

.extensionObject



74
75
76
# File 'lib/rails-gallery/rgallery/photo.rb', line 74

def extension
  @extension ||= :png
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
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



59
60
61
# File 'lib/rails-gallery/rgallery/photo.rb', line 59

def alt
  'no alt'
end

#descriptionObject



63
64
65
# File 'lib/rails-gallery/rgallery/photo.rb', line 63

def description
  'no description'
end

#extensionObject



67
68
69
# File 'lib/rails-gallery/rgallery/photo.rb', line 67

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

#file_pathObject



43
44
45
# File 'lib/rails-gallery/rgallery/photo.rb', line 43

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

#filenameObject



39
40
41
# File 'lib/rails-gallery/rgallery/photo.rb', line 39

def filename
  id
end

#pathObject



47
48
49
# File 'lib/rails-gallery/rgallery/photo.rb', line 47

def path
  file_path
end

#source_photosObject

A photo can contain a source set of other photos!



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

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



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

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)


21
22
23
# File 'lib/rails-gallery/rgallery/photo.rb', line 21

def srcset?
  !srcset.blank?
end

#thumbObject



51
52
53
# File 'lib/rails-gallery/rgallery/photo.rb', line 51

def thumb
  path
end

#titleObject



55
56
57
# File 'lib/rails-gallery/rgallery/photo.rb', line 55

def title
  'no title'
end