Class: Babik::Selection::Operation::WeekDay

Inherits:
DateOperation show all
Defined in:
lib/babik/queryset/lib/selection/operation/date.rb

Overview

WeekDay (1-7, sunday to monday) date operation

Constant Summary

Constants inherited from DateOperation

DateOperation::HAS_OPERATOR

Constants included from ValidDBMS

ValidDBMS::SUPPORTED_DB_ADAPTERS

Instance Attribute Summary

Attributes inherited from Base

#field, #sql_operation, #sql_operation_template, #value

Instance Method Summary collapse

Methods included from ValidDBMS

#assert_dbms

Methods inherited from Base

#_init_sql_operation, date_special_cases, #db_engine, escape, factory, initialize_operation, initialize_operators, operator?, special_cases, #to_s

Constructor Details

#initialize(field, operator, value) ⇒ WeekDay

Returns a new instance of WeekDay.



102
103
104
105
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 102

def initialize(field, operator, value)
  value = format('%d', value) if db_engine == 'sqlite3'
  super(field, operator, value)
end

Instance Method Details

#sql_functionObject

Raises:

  • (NotImplementedError)


107
108
109
110
111
112
113
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 107

def sql_function
  dbms_adapter = db_engine
  return 'DAYOFWEEK(#field) -  1' if dbms_adapter == 'mysql2'
  return 'EXTRACT(DOW FROM #field)' if dbms_adapter == 'postgresql'
  return 'strftime(\'%w\', #field)' if dbms_adapter == 'sqlite3'
  raise NotImplementedError, "#{self.class} lookup not implemented for #{dbms_adapter}"
end