Sha256: b2af9a9a7edcc19112a803bcdeff0b6a50132eaa4b3fc6eb42de749fc500b00c

Contents?: true

Size: 905 Bytes

Versions: 17

Compression:

Stored size: 905 Bytes

Contents

require "file_scanner/refinements"

module FileScanner
  using Refinements
  module Filters
    def self.defaults
      constants.map do |name|
        self.const_get(name).new
      end
    end

    class LastAccess
      DAY = 3600*24

      def initialize(atime = Time.now-30*DAY)
        @atime = atime
      end

      def call(file)
        @atime >= File.atime(file)
      end
    end

    class MatchingName
      def initialize(regexp = nil)
        @regexp = compile(regexp)
      end

      def call(file)
        return unless @regexp
        File.basename(file).matches?(@regexp)
      end

      private def compile(regexp)
        return unless regexp
        Regexp.compile(regexp.to_s)
      end
    end

    class SizeRange
      def initialize(min: 0, max: 5*1024)
        @range = min..max
      end

      def call(file)
        @range === File.size(file)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
file_scanner-3.2.5 lib/file_scanner/filters.rb
file_scanner-3.2.4 lib/file_scanner/filters.rb
file_scanner-3.2.3 lib/file_scanner/filters.rb
file_scanner-3.2.2 lib/file_scanner/filters.rb
file_scanner-3.2.1 lib/file_scanner/filters.rb
file_scanner-3.2.0 lib/file_scanner/filters.rb
file_scanner-3.1.0 lib/file_scanner/filters.rb
file_scanner-3.0.1 lib/file_scanner/filters.rb
file_scanner-2.3.0 lib/file_scanner/filters.rb
file_scanner-2.2.1 lib/file_scanner/filters.rb
file_scanner-2.1.1 lib/file_scanner/filters.rb
file_scanner-2.1.0 lib/file_scanner/filters.rb
file_scanner-2.0.4 lib/file_scanner/filters.rb
file_scanner-2.0.3 lib/file_scanner/filters.rb
file_scanner-2.0.2 lib/file_scanner/filters.rb
file_scanner-2.0.1 lib/file_scanner/filters.rb
file_scanner-1.1.0 lib/file_scanner/filters.rb