Class: RailsAdmin::AbstractModel::StatementBuilder::FilteringDuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/abstract_model.rb

Instance Method Summary collapse

Constructor Details

#initialize(operator, value) ⇒ FilteringDuration

Returns a new instance of FilteringDuration.



226
227
228
229
# File 'lib/rails_admin/abstract_model.rb', line 226

def initialize(operator, value)
  @value = value
  @operator = operator
end

Instance Method Details

#betweenObject



259
260
261
# File 'lib/rails_admin/abstract_model.rb', line 259

def between
  [@value[1], @value[2]]
end

#defaultObject



263
264
265
# File 'lib/rails_admin/abstract_model.rb', line 263

def default
  [default_date, default_date]
end

#get_durationObject



231
232
233
234
235
236
237
238
239
240
# File 'lib/rails_admin/abstract_model.rb', line 231

def get_duration
  case @operator
  when 'between'   then between
  when 'today'     then today
  when 'yesterday' then yesterday
  when 'this_week' then this_week
  when 'last_week' then last_week
  else default
  end
end

#last_weekObject



254
255
256
257
# File 'lib/rails_admin/abstract_model.rb', line 254

def last_week
  [1.week.ago.to_date.beginning_of_week,
   1.week.ago.to_date.end_of_week]
end

#this_weekObject



250
251
252
# File 'lib/rails_admin/abstract_model.rb', line 250

def this_week
  [Date.today.beginning_of_week, Date.today.end_of_week]
end

#todayObject



242
243
244
# File 'lib/rails_admin/abstract_model.rb', line 242

def today
  [Date.today, Date.today]
end

#yesterdayObject



246
247
248
# File 'lib/rails_admin/abstract_model.rb', line 246

def yesterday
  [Date.yesterday, Date.yesterday]
end