class Snippr::SegmentFilter::ValidBetween

Public Instance Methods

active?() click to toggle source
# File lib/snippr/segment_filter/valid_between.rb, line 4
def active?
  Snippr::Clock.now.to_s >= valid_from && Snippr::Clock.now.to_s <= valid_until
rescue ArgumentError
  false
end

Private Instance Methods

valid_from() click to toggle source
# File lib/snippr/segment_filter/valid_between.rb, line 12
def valid_from
  @valid_from ||= DateTime.strptime(@filter_value, "%Y-%m-%d %H:%M").to_s
end
valid_until() click to toggle source
# File lib/snippr/segment_filter/valid_between.rb, line 16
def valid_until
  @valid_until ||= begin
    date_until = @filter_value.match(/([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}(?::[0-9]{2})?)$/)
    raise ArgumentError.new("valid_until date not parsable. Full filter value was: '#{@filter_value}'") if date_until.nil?
    DateTime.strptime(date_until[1], "%Y-%m-%d %H:%M").to_s
  end
end