GithubHelp home page GithubHelp logo

acts_as_matchable's Introduction

ActsAsMatchable

Use regular expression patterns to match one or more attributes of an object with a single method: pattern_match(regex).

I owe thanks to bsampietro (Bruno Sampietro) for his example on ActsAsSearchable. See: github.com/bsampietro/acts_as_searchable

ActsAsMatchable is similar to ActsAsSearchable with the following differences:

  • Rather than full or partial text matching, ActsAsMatchable is designed to support pattern and regular expression matching against one or more attributes of a ruby object. So, you can find patterns like phone numbers, email addresses,tax ids, etc that may appear in various attributes of an object.

  • ActsAsMatchable is used to extend ActiveRecord objects however it does not utilize any SQL thus making it database agnostic.

  • Matched attributes (if any) are returned from the pattern_match method call as a hash in the format {:col_name => value}

Install

Before you install this plugin, make sure you have the rspec-plugin-generator and rspec-rails plugins if you don’t already (and you really should ;)

script/plugin install git://github.com/dchelimsky/rspec-rails.git
script/plugin install git://github.com/patmaddox/rspec-plugin-generator.git

Currently, this only exists as a Rails plugin, so:

script/plugin install git://github.com/terryjray/acts_as_matchable

Synopsis

class BlogComment < ActiveRecord::Base

    acts_as_matchable :all

end

# we can find phone numbers in any of the blog comment fields
phone_numbers = comment.pattern_match(/\d\d\d[-]\d\d\d[-]\d\d\d\d/)

# to specify certain fields (not all) just include the last after the declaration
acts_as_matchable :first_name,:last_name,:description

Contributing

Feel free to pitch in. You know the drill:

1. Fork the project.
2. Create a topic branch.
3. Implement your feature or bug fix.
4. Please at least add a test in the rspec file that demonstrates your addition
5. Commit and push your changes.
6. Submit a pull request.

I’ll do my best to keep up. Thx!

More Info

For an extended example, updates, and probably more detail than you’d ever need outside the source itself, you can see my announcement for the project at terryjray.blogspot.com/2011/02/introducing-actsasmatchable-plugin.html

Copyright © 2011 Centrix Information Solutions, LLC, released under the MIT license

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.