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


188
189
190
191
# File 'lib/rails_admin/abstract_model.rb', line 188

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

Instance Method Details

#betweenObject


221
222
223
# File 'lib/rails_admin/abstract_model.rb', line 221

def between
  [convert_to_date(@value[1]), convert_to_date(@value[2])]
end

#defaultObject


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

def default
  [default_date, default_date]
end

#get_durationObject


193
194
195
196
197
198
199
200
201
202
# File 'lib/rails_admin/abstract_model.rb', line 193

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


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

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

#this_weekObject


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

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

#todayObject


204
205
206
# File 'lib/rails_admin/abstract_model.rb', line 204

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

#yesterdayObject


208
209
210
# File 'lib/rails_admin/abstract_model.rb', line 208

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