Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

regex_sieve

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regex_sieve

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

RegexSeive

The RegexSieve functions in a manner similar a hash. The regex sieve is initialized with a hash where the keys are regular expressions and the values can be any valid Ruby object. The order of the keys matters. When the regex sieve is accessed using the array accessor [], it returns the first matching record.

sieve = RegexSieve.new({
  /(Invincible|Born & Raised) IPA/ => 'Craft IPA',
  /(Fresh Squeezed) IPA/           => 'Microbrew IPA',
  /IPA/                            => 'Other IPA'
})

sieve['Invincible IPA'] # => 'Craft IPA'
sieve['Awesome IPA']    # => 'Other IPA'
sieve['Kinda Pale Ale'] # => nil

By default, only the values are returned, but the key and all matching capture groups can optionally be returned.

result_and_match = sieve['Invincible IPA', :match]   # => {:value=>"Craft IPA", :match=>#<MatchData "Invincible IPA" 1:"Invincible">}
result_and_match[:match][1]                          # => 'Invincible'

result_and_key = sieve['Invincible IPA', :regex]     # => {:value=>"Craft IPA", :regex=>/(Invincible|Born & Raised) IPA/}

result_all = sieve['Invincible IPA', :regex, :match] # => {:value=>"Craft IPA", :regex=>/(Invincible|Born & Raised) IPA/, :match=>#<MatchData "Invincible IPA" 1:"Invincible">}

FAQs

Package last updated on 05 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc