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.



195
196
197
198
# File 'lib/rails_admin/abstract_model.rb', line 195

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

Instance Method Details

#betweenObject



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

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

#defaultObject



232
233
234
# File 'lib/rails_admin/abstract_model.rb', line 232

def default
  [default_date, default_date]
end

#get_durationObject



200
201
202
203
204
205
206
207
208
209
# File 'lib/rails_admin/abstract_model.rb', line 200

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



223
224
225
226
# File 'lib/rails_admin/abstract_model.rb', line 223

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

#this_weekObject



219
220
221
# File 'lib/rails_admin/abstract_model.rb', line 219

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

#todayObject



211
212
213
# File 'lib/rails_admin/abstract_model.rb', line 211

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

#yesterdayObject



215
216
217
# File 'lib/rails_admin/abstract_model.rb', line 215

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