Sha256: b03773f538e21703705ec500362be9c43774ca987ad57e9f869d76306220a432

Contents?: true

Size: 1.31 KB

Versions: 25

Compression:

Stored size: 1.31 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 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 >= 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

25 entries across 25 versions & 1 rubygems

Version Path
trusty-festivity-extension-2.3.21 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.20 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.19 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.18 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.17 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.16 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.15 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.14 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.13 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.12 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.11g lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.10 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.9 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.8 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.7 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.6 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.5 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.4 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.3 lib/festivity/extensions/site_extensions.rb
trusty-festivity-extension-2.3.2 lib/festivity/extensions/site_extensions.rb