Sha256: ed06d3357f62f25391ebde9d74136485a1efe04cfb3b848fa3ece4ebc37d8bd6

Contents?: true

Size: 1.5 KB

Versions: 24

Compression:

Stored size: 1.5 KB

Contents

module Festivity
  module Extensions
    module SiteExtensions

      def self.included(base)
        base.class_eval {
          has_many :festivity_category_types
          include Festivity::Extensions::SiteExtensions::SiteMethods
        }
      end

      module SiteMethods

        def festivity_start_date=(value)
          super(Chronic.parse(value))
        end

        def festivity_end_date=(value)
          super(Chronic.parse(value))
        end

        def festivity_active_category_types()
          self.festivity_category_types.where(["inactive = false"])
        end

        def festivity_active_category_types_for(page_class)
          self.festivity_category_types.where(["inactive = false AND page_class = '#{page_class}'"])
        end

        def date_during_festival?(date)
          self.festival_datetimes.any? {|festival_date| festival_date.datetime == date}
        end

        def festival_datetimes
          @festival_datetimes ||= calculate_festival_datetimes
        end

        def calculate_festival_datetimes
          dates = [self.festivity_start_date]
          advance_by = date_filter? ? {days: 1} : {hours: 1}
          until dates.last.advance(advance_by) >= self.festivity_end_date do
            dates << dates.last.advance(advance_by)
          end
          FestivityDatetimeFilterPresenter.new(dates, self.festivity_filter_type)
        rescue
          []
        end

        def date_filter?
          self.festivity_filter_type == "date"
        end

      end

    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
trusty-festivity-extension-2.6.3 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.6.2 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.6.1 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.6 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.19 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.18 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.17 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.16 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.15 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.14 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.13 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.12 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.11 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.10 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.9 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.8 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.7 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.6 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.5 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.5.4 lib/festivity/extensions/site_extensions.rb