Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmromer/pattern_matcher
A TDD / OOP demo in Ruby
https://github.com/jmromer/pattern_matcher
demo oop rspec ruby tdd
Last synced: 5 days ago
JSON representation
A TDD / OOP demo in Ruby
- Host: GitHub
- URL: https://github.com/jmromer/pattern_matcher
- Owner: jmromer
- Created: 2015-07-04T06:25:17.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-22T22:01:21.000Z (over 7 years ago)
- Last Synced: 2023-08-05T16:38:42.669Z (over 1 year ago)
- Topics: demo, oop, rspec, ruby, tdd
- Language: Ruby
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Pattern Matcher
===============Purpose
-------A command-line utility that takes input from STDIN in the following format:
```
6
*,b,*
a,*,*
*,*,c
foo,bar,baz
w,x,*,*
*,x,y,z
5
/w/x/y/z/
a/b/c
foo/
foo/bar/
foo/bar/baz/
```And produces output as follows:
```
*,x,y,z
a,*,*
NO MATCH
NO MATCH
foo,bar,baz
```Matching each of the given paths (e.g. `/a/b/c`) with the best-fitting pattern that
matches it (e.g. `a,b,c`).Manual Testing
--------------```sh
cat data/input.txt | bin/pattern_match
```Output:
```
*,x,y,z
a,*,*
NO MATCH
NO MATCH
foo,bar,baz
```Test Suite
----------```
PatternMatcher::InputParser
#parse
given valid input
correctly parses patterns
correctly parses paths
correctly parses the number of patterns and paths
given invalid input
raises an error unless the given numbers are valid
raises an error unless given exactly two digit-linesPatternMatcher::Analyzer
#best_fitting_pattern_for
returns the highest-scoring pattern for a/b/c
returns the highest-scoring pattern for /w/x/y/z/
returns the NO MATCH for foo/bar/
returns the NO MATCH for foo/
returns the highest-scoring pattern for foo/bar/baz/PatternMatcher::Pattern
::build
returns an array of Pattern objects
#to_a
returns the parsed pattern, as an array
#pattern
parses a passed-in pattern stringPatternMatcher::Path
::build
returns an array of Path objects
#path
ignores leading and trailing slashes
parses a passed-in path string
#to_a
returns the parsed path, as an arrayPatternMatcher::Matcher
is sortable by pattern string, in descending order by default
#pattern_string
returns the pattern as a string
::build
builds a collection of Matcher objects
#evaluate
compares a path to a given pattern, yielding a score
given a 4-segment pattern
proportionately penalizes score for an unmatched segment
penalizes half-credit for a wildcard match
given a 3-segment pattern
penalizes half-credit for a wildcard match
proportionately penalizes score for an unmatched segment
zeroes score for mismatch in number of segmentsFinished in 0.02623 seconds (files took 0.49902 seconds to load)
26 examples, 0 failuresRandomized with seed 3352
```