Sha256: df1b46618cb3111ce97c3c17a85b87b4b8af9eaeb3ee02909e58d14978f2ab6d

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# Copyright (c) 2013-2015 SUSE LLC
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 3 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact SUSE LLC.
#
# To contact SUSE about this file by physical or electronic mail,
# you may find current contact information at www.suse.com

class ElementFilter
  attr_accessor :path, :matchers

  def initialize(path, matchers = nil)
    @path = path
    @matchers = []

    raise("Wrong type") if ![NilClass, String, Array].include?(matchers.class)

    add_matchers(matchers) if matchers
  end

  def add_matchers(matchers)
    @matchers += Array(matchers)
  end

  def matches?(value)
    @matchers.each do |matcher|
      if matcher.end_with?("*")
        return true if value.start_with?(matcher[0..-2])
      else
        return true if value == matcher
      end
    end

    false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
machinery-tool-1.5.0 lib/element_filter.rb