Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nathanl/sequences
Demo code - solution to https://gist.github.com/pedromartinez/7788650
https://github.com/nathanl/sequences
Last synced: 12 days ago
JSON representation
Demo code - solution to https://gist.github.com/pedromartinez/7788650
- Host: GitHub
- URL: https://github.com/nathanl/sequences
- Owner: nathanl
- License: mit
- Created: 2015-11-04T17:12:23.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-04T17:28:50.000Z (about 9 years ago)
- Last Synced: 2023-03-11T11:48:41.618Z (over 1 year ago)
- Language: Ruby
- Size: 133 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Sequences
A solution to https://gist.github.com/pedromartinez/7788650
Given lines of words, `Sequence::Builder` will find all N-letter sequences that occur in only one input word, and lets you see the alphabetized sequences and the word in which each one was found. The default sequence length is 4.
Finds only sequences of letters (`/[A-Za-z]/`) - excluding, for example, numbers, apostrophes, period and ampersands.
For executable documentation, run `rspec spec --format doc`.
## Usage from Ruby
Initialize `Sequence::Builder` with an `IO` object - for example, a `File`, a `StringIO`, or `STDIN`. Then call `#sequences` and/or `#words` to see the analyzed output.
For example, from `bin/console`:
```ruby
>> sb = Sequences::Builder.new(StringIO.new("arrows\ncarrots\ngive\nme"), 2)
=> #"carrots", "gi"=>"give", "iv"=>"give", "me"=>"me", "ot"=>"carrots", "ow"=>"arrows", "ts"=>"carrots", "ve"=>"give", "ws"=>"arrows"}>
>> sb.sequences
#=> ["carr", "give", "rots", "rows", "rrot", "rrow"]
>> sb.words
=> ["carrots", "give", "carrots", "arrows", "carrots", "arrows"]
```You may optionally provide a sequence length.
```ruby
>> sb = Sequences::Builder.new(StringIO.new("arrows\ncarrots\ngive\nme"), 2)
#=> #"carrots", "gi"=>"give", "iv"=>"give", "me"=>"me", "ot"=>"carrots", "ow"=>"arrows", "ts"=>"carrots", "ve"=>"give", "ws"=>"arrows"}>
>> sb.sequences
=> ["ca", "gi", "iv", "me", "ot", "ow", "ts", "ve", "ws"]
>> sb.words
=> ["carrots", "give", "give", "me", "carrots", "arrows", "carrots", "give", "arrows"]
```## Command-line Usage
To use as a script, pipe input to `bin/sequences`. For example:
`cat /usr/share/dict/words | bin/sequences`
You can set `OUTPUT_DIR` and `SEQUENCE_LENGTH` environment variables if you wish.