No commit activity in last 3 years
No release in over 3 years
wildcard matchers
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
>= 0

Runtime

 Project Readme

wildcard_matchers Build Status Dependency Status Coverage Status

General Usage

require "wildcard_matchers"

WildcardMatchers.wildcard_match?("string", /str/) #=> true

require "wildcard_matchers/rspec"

describe "wildcard_matcher" do
  it "should wildcard match" do
    { :a => [ "hoge", "fuga" ] }.should wildcard_match(:a => [ is_a_string, /^fu/ ])
  end
end

See specs, for more detail.

wildcard matchers

  • is_a(class)
  • is_a(String) === String #=> true
  • is_a_string === String #=> true
  • is_bool
  • is_bool === true #=> true
  • is_bool === false #=> true
  • is_bool === object #=> false
  • is_time
  • is_time === "2012-05-13" #=> true
  • is_uri
  • is_uri(:host => "example.com") === "http://example.com" #=> true
  • with_uri_template
  • with_uri_template("http://example.com/users/{id}", "id" => "1") === "http://example.com/users/1" #=> true
  • with_uri_template("http://example.com/users{?id}", "id" => "1") === "http://example.com/users?id=1" #=> true
  • with_uri_template and witout_query!
  • with_uri_template("http://example.com/users", "id" => "1").without_query! === "http://example.com/users?id=1" #=> true
  • hash_includes
  • hash_includes(:a) === { :a => 1 } #=> true
  • hash_includes(:b) === { :a => 1 } #=> false
  • hash_includes(:a => Integer) === { :a => 1 } #=> true
  • hash_includes(:a => 2) === { :a => 1 } #=> false
  • is_a_member_of
  • is_a_member_of(0, 1) === 0 #=> true
  • bag_of
  • sored array comparison (Note: each item should comparable with every other item)

helpers

  • nil_or
  • nil_or(is_a_string) === nil #=> true
  • nil_or(is_a_string) === "a" #=> true
  • any_of
  • any_of(String, /b/) === "a" #=> true
  • any_of(Integer, /b/) === "a" #=> false
  • all_of
  • all_of(String, /a/) === "a" #=> true
  • all_of(String, /b/) === "a" #=> false
  • for_all
  • for_all(is_a_string) === %w[ a b c ] #=> true
  • for_any
  • for_any(is_a_string) === [ 1, "1" ] #=> true
  • responding
  • responding(next: 2) === 1 #=> true (because 1.next #=> 2)

composite matchers

  • using &
  • for_all(is_a_string) & for_any(/hoge/) # every element is String and one matched /hoge/
  • using |
  • for_all(is_a_string) | for_all(is_a_integer) # every element is String or Integer

How it works

It is very simple. Recursive match using ===, and Class, Range, and Proc act as wildcard matchers.

You can create original matcher using lambda.

original_matcher = lamda do |actual|
  (…as you like…)
end

wildcard_matcher?("actual", original_matcher)

Installation

Add this line to your application's Gemfile:

gem 'wildcard_matchers'

And then execute:

$ bundle

Or install it yourself as:

$ gem install wildcard_matchers

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request