Giter VIP home page Giter VIP logo

pattern_expander's Introduction

Pattern Expander

Installation

Add this line to your application's Gemfile:

gem 'pattern_expander'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pattern_expander

Usage

Takes patterns and outputs their combinations - think reverse regex. Lazily loads "pages" of combinations and returns results before the heat death of the universe.

Pass in a string with randomly chosen values in square brackets"[]":

expander = PatternExpander.new(
  "My [startup|band|puppy's] name is [i|e||Power |Awesome ][Ninja|Rockstar] [Ministry|Labs|Quux]"
)

Get random samples with #sample:

expander.sample # my startup name is Power Rockstar Ministry
expander.sample # my puppy's name is iNinja Labs
expander.sample(3) # get multiple samples

Get specific index values:

expander = PatternExpander.new("[a|b][1|2]")
expander[0] # "a1"
expander[1] # "a2"
expander[0..3] # ["a1", "a2", "b1", "b2"]

By default you can use "+d" and "+w" to map to digits and alphanumeric characters. Here's an example of constructing a big UUID like pattern:

expander = PatternExpander.new(
  "[+w][+w][+w][+w]-[+w][+w][+w][+w]-[+w][+w][+w][+w]-[+w][+w][+w][+w]"
)
expander.sample # "eo6a-68m6-coxw-14j7"
expander[10_000_000_000..10_000_000_002]
# returns ["aaaa-aaaa-aaaa-ahz2", "aaaa-aaaa-aaaa-ahz3", "aaaa-aaaa-aaaa-ahz4"]

And you can pass your own substitutes in and come up with your next startup elevator pitch:

expander = PatternExpander.new("It's like [+company] for [+customer]",
  substitutes: {
   '+company' =>  ['Chat Roulette',  'Kickstarter', 'Stack Overflow', 'SpaceX'],
   '+customer' => ['Texas', 'pets', 'tweens', 'magicians', 'figure skaters']
  }
)
expander.sample # It's like Chat Roulette for magicians
expander.sample # It's like Stack Overflow for Texas
expander.sample # It's like SpaceX for figure skaters

TODO

  • Sample should return any value only once
  • Error when max range has been exceeded for the index
  • Delegate methods from PatternExpander to CombinationIndex
  • API for adding substitutes
  • PatternExpander#all(max:n)
  • Filters (e.g. matches pattern, not in exclusion set, max length)
  • Ranges for filtered results

Contributing

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

pattern_expander's People

Contributors

aquabu avatar harlantwood avatar

Watchers

 avatar

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.