Class: RGallery::Page
- Inherits:
-
PhotoConfig
- Object
- PhotoConfig
- RGallery::Page
- Includes:
- Enumerable
- Defined in:
- lib/rails-gallery/rgallery/page.rb
Instance Attribute Summary
Attributes inherited from PhotoConfig
Class Method Summary collapse
-
.from_source(sources) ⇒ Object
a source is a hash of the form: ‘banner’ => [‘banner-HD’, sizing: ‘2x’, ‘banner-phone’, sizing: ‘100w’] see: add_photo_sources.
Instance Method Summary collapse
- #<<(photo_objs) ⇒ Object
- #add_photo_sources(sources_hash) ⇒ Object
- #add_photo_w_sources(source) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(photo_objs = [], options = {}) ⇒ Page
constructor
A new instance of Page.
- #photo_objs ⇒ Object
- #photos ⇒ Object
Constructor Details
#initialize(photo_objs = [], options = {}) ⇒ Page
Returns a new instance of Page.
5 6 7 8 |
# File 'lib/rails-gallery/rgallery/page.rb', line 5 def initialize photo_objs = [], = {} @photo_objs = photo_objs super end |
Class Method Details
.from_source(sources) ⇒ Object
a source is a hash of the form: ‘banner’ => [‘banner-HD’, sizing: ‘2x’, ‘banner-phone’, sizing: ‘100w’] see: add_photo_sources
13 14 15 16 17 18 19 |
# File 'lib/rails-gallery/rgallery/page.rb', line 13 def self.from_source sources page = self.create sources.keys, @photos ||= sources.map do |key, srclist| photo_class.new key, .merge(:sources => srclist) end end |
Instance Method Details
#<<(photo_objs) ⇒ Object
21 22 23 24 |
# File 'lib/rails-gallery/rgallery/page.rb', line 21 def << photo_objs @photo_objs ||= [] @photo_objs += [photo_objs].flatten end |
#add_photo_sources(sources_hash) ⇒ Object
26 27 28 29 30 |
# File 'lib/rails-gallery/rgallery/page.rb', line 26 def add_photo_sources sources_hash sources_hash.each do |source| add_photo_w_sources source end end |
#add_photo_w_sources(source) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rails-gallery/rgallery/page.rb', line 32 def add_photo_w_sources source raise ArgumentError, "Must be a hash, was: #{source}" unless source.kind_of? Hash key = source.keys.first srclist = source.values.first raise ArgumentError, "Hash value must be an Array, was: #{srclist}" unless srclist.kind_of? Array self.send :<<, key @photos ||= [] @photos << photo_class.new(key, .merge(:sources => srclist)) end |
#each(&block) ⇒ Object
53 54 55 |
# File 'lib/rails-gallery/rgallery/page.rb', line 53 def each &block photos.each {|photo| yield photo } end |
#photo_objs ⇒ Object
43 44 45 |
# File 'lib/rails-gallery/rgallery/page.rb', line 43 def photo_objs @photo_objs ||= [] end |
#photos ⇒ Object
47 48 49 |
# File 'lib/rails-gallery/rgallery/page.rb', line 47 def photos @photos ||= photo_objs.map {|obj| photo_class.new obj, } end |