Module: BannerRotator::PageExtensions
- Defined in:
- lib/banner_rotator/page_extensions.rb
Class Method Summary collapse
Instance Method Summary collapse
- #banner_placements_with_inheritance ⇒ Object
- #banners_assigned? ⇒ Boolean
- #banners_inherited? ⇒ Boolean
- #select_banner ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/banner_rotator/page_extensions.rb', line 3 def self.included(base) base.class_eval do has_many :banner_placements has_many :banners, :through => :banner_placements alias_method_chain :banner_placements, :inheritance after_destroy :remove_assigned_banner_placements end end |
Instance Method Details
#banner_placements_with_inheritance ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/banner_rotator/page_extensions.rb', line 20 def if .empty? && parent parent. else end end |
#banners_assigned? ⇒ Boolean
12 13 14 |
# File 'lib/banner_rotator/page_extensions.rb', line 12 def && ! .empty? end |
#banners_inherited? ⇒ Boolean
16 17 18 |
# File 'lib/banner_rotator/page_extensions.rb', line 16 def && .empty? && .count > 0 end |
#select_banner ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/banner_rotator/page_extensions.rb', line 28 def @banners_with_weighting ||= .map do |p| [p.] * p.weight end.flatten x = rand(@banners_with_weighting.size) = @banners_with_weighting[x] @banners_with_weighting.delete(x+1) end |