Class: RGallery::Photo
- Inherits:
-
Object
- Object
- RGallery::Photo
- Defined in:
- lib/rails-gallery/rgallery/photo.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
-
#obj ⇒ Object
(also: #id)
readonly
Returns the value of attribute obj.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#sizing ⇒ Object
readonly
Returns the value of attribute sizing.
-
#sources ⇒ Object
Returns the value of attribute sources.
Instance Method Summary collapse
- #alt ⇒ Object
- #description ⇒ Object
- #extension ⇒ Object
- #file_path ⇒ Object
- #filename ⇒ Object
-
#initialize(obj, options = {}) ⇒ Photo
constructor
A new instance of Photo.
- #path ⇒ Object
-
#source_photos ⇒ Object
A photo can contain a source set of other photos!.
-
#srcset ⇒ Object
map [‘banner-HD.jpeg’, sizing: ‘2x’, ‘banner-phone.jpeg’, sizing: ‘100w’] into -> “banner-HD.jpeg 2x, banner-phone.jpeg 100w.
- #srcset? ⇒ Boolean
- #thumb ⇒ Object
- #title ⇒ Object
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, = {} @obj = obj self.sources = .delete :sources @sizing = .delete :sizing @options = end |
Class Attribute Details
.extension ⇒ Object
76 77 78 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 76 def extension @extension ||= :png end |
Instance Attribute Details
#obj ⇒ Object (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 |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 3 def @options end |
#sizing ⇒ Object (readonly)
Returns the value of attribute sizing.
3 4 5 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 3 def sizing @sizing end |
#sources ⇒ Object
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
#alt ⇒ Object
61 62 63 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 61 def alt 'no alt' end |
#description ⇒ Object
65 66 67 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 65 def description 'no description' end |
#extension ⇒ Object
69 70 71 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 69 def extension [:extension] || self.class.extension end |
#file_path ⇒ Object
45 46 47 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 45 def file_path "#{filename}.#{extension}" end |
#filename ⇒ Object
41 42 43 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 41 def filename id end |
#path ⇒ Object
49 50 51 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 49 def path file_path end |
#source_photos ⇒ Object
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, .merge(:sizing => source.sizing) end end |
#srcset ⇒ Object
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
23 24 25 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 23 def srcset? !srcset.blank? end |
#thumb ⇒ Object
53 54 55 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 53 def thumb path end |
#title ⇒ Object
57 58 59 |
# File 'lib/rails-gallery/rgallery/photo.rb', line 57 def title 'no title' end |