Sha256: 6c6a234eec1fef262e1f10324b3c27e1f64ef698085932738e0daee7a8966c32

Contents?: true

Size: 903 Bytes

Versions: 218

Compression:

Stored size: 903 Bytes

Contents

module Eco
  module Data
    module Files
      class FilePattern
        def initialize(file = "")
          @source_file = file
        end

        def resolve(dir: nil, start: "")
          pattern(dir).gsub('*', start)
        end

        def match?(file, dir: nil)
          /#{Regexp.escape(self.pattern(dir))}/i.match?(file)
        end

        def any?(files, dir: nil)
          return false unless files.is_a?(Array)
          files.any? { |file|  match?(file, dir: dir) }
        end

        def pattern(dir = nil)
          return File.join(dir, "*") if @source_file.to_s.empty?
          filename = File.basename(@source_file)
          path = File.dirname(@source_file)
          path = File.join(dir, path) if dir
          wildcard = (filename =~ /\*/)? "" : "*"
          File.join(path, wildcard + filename)
        end
      end
    end
  end
end

Version data entries

218 entries across 218 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.20 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.19 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.18 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.17 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.16 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.15 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.14 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.13 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.12 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.11 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.10 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.9 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.8 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.7 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.6 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.5 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.4 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.3 lib/eco/data/files/file_pattern.rb
eco-helpers-3.0.2 lib/eco/data/files/file_pattern.rb