Sha256: eff920c8675c1bd2102463e0aa343fcb4e51b9225fb6de86aab624a96c596f60

Contents?: true

Size: 840 Bytes

Versions: 1

Compression:

Stored size: 840 Bytes

Contents

# frozen_string_literal: true

require_relative '../base_adapter'

class ActiveSet
  class FilterProcessor < BaseProcessor
    class EnumerableAdapter < BaseAdapter
      def process(set)
        set.select do |item|
          value_for(item).send(@instruction.operator,
                               passed_value)
        end
      end

      private

      def value_for(item)
        convert_datetime_values_to_integer(@instruction.value_for(item: item))
      end

      def passed_value
        convert_datetime_values_to_integer(@instruction.value)
      end

      def convert_datetime_values_to_integer(value)
        # DateTimes (and Times) are tricky to compare, Integers are easier
        # and I only care about second precision
        return value unless value.is_a?(DateTime)
        value.to_i
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activeset-0.3.1 lib/active_set/processors/filter/enumerable_adapter.rb