Sha256: d16904dde05194bc9e23b2c52927126eadae6efa47f6121d3b0d0767c63d44a7

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

module Searchgasm
  module Condition
    class DuringEvening < Base
      class << self
        def name_for_column(column)
          return unless time_column?(column)
          super
        end
        
        def aliases_for_column(column)
          column_names = [column.name]
          column_names << column.name.gsub(/_(at|on)$/, "") if column.name =~ /_(at|on)$/
          
          aliases = []
          column_names.each { |column_name| aliases += ["#{column_name}_in_the_evening", "#{column_name}_in_evening", "#{column_name}_evening"] }
          aliases << "#{column_names.last}_during_evening" if column_names.size > 1
          aliases
        end
      end
      
      def to_conditions(value)
        evening_start = 17
        evening_end = 22
        
        # Need to set up a funcion in each adapter for dealing with dates. Mysql uses HOUR(), sqlite uses strftime(), postgres uses date_part('hour', date). Could potentially be a pain in the ass.
        # Also, you could set up an hour = condition, and leverage that to do this.
        if value == true
          ["#{quoted_table_name}.#{quoted_column_name} >= ? AND #{quoted_table_name}.#{quoted_column_name} <= ?", value]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
searchgasm-1.2.2 lib/searchgasm/condition/during_evening.rb