Sha256: 30373c25d7f164004b821cbfb9efdf74a12eb34713edddbb4551e78dd6002cd4

Contents?: true

Size: 623 Bytes

Versions: 11

Compression:

Stored size: 623 Bytes

Contents

require_relative '../filter_decorator.rb'

class Has_not_field_filter_decorator < Filter_decorator
  def initialize(filter, field)
    super(filter)
    self.field = field
  end

  def apply(filtering_obj)
    if filtering_obj.is_a?(Array)
      super(filtering_obj).select do |student|
        student_value = student.send(self.field).to_s
        student_value.nil? || student_value.empty?
      end
    else
      query = super(filtering_obj)
      condition = query.include?("WHERE") ? "AND" : "WHERE"
      "#{query} #{condition} (#{field} = '' OR #{field} IS NULL)"
    end
  end

  private
  attr_accessor :field
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
student_mvp-0.1.10 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.9 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.8 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.7 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.6 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.5 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.4 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.3 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.2 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.1 lib/models/filter/student_filters/has_not_field_filter_decorator.rb
student_mvp-0.1.0 lib/models/filter/student_filters/has_not_field_filter_decorator.rb