Git Product home page Git Product logo

spoonerize's Introduction

Welcome to Spoonerize -- a word game.

Build Status Gem Version License: MIT

Spoonerism [noun] a verbal error in which a speaker accidentally transposes the initial sounds or letters of two or more words, often to humorous effect.

You can view the documentation here

About

We've all done it; someone says a phrase, and you flip the first few letters around, and sometimes, it makes an even funnier phrase. For example: "Tomb Raider" becomes "Romb Taider". Well, when I was in high school, we took it further -- probably too far -- and made a rule set. This gem, which includes a command-line executable, follows those rules, which are:

  • Each word drops its leading consonant group and takes the leading consonant group of the next word.
  • If the word has no leading consonants, nothing is dropped, but it still receives the next word's leading consonants if it has any.
  • If the next word has no leading consonants, the current word receives no consonants, but will still lose its own if it has any.
  • When being "lazy", common words ("the", "his", etc.) remain unchanged.
  • If the word to pull from is excluded, that word is skipped, and you pull the leading consonants from the next non-excluded word.
  • "Q" and "U" should stay together (like "queen").
  • A lot of the time, the words won't look how they're supposed to sound, as you go by how the word used to sound, not how it's spelled. For instance, $ spoonerize two new cuties becomes "no cew twuties", but it would be pronounced "new coo tooties", as the words retain their original sounds.

Installation

Automated

Just install the gem!

gem install spoonerize

If you don't have permission on your system to install ruby or gems, I recommend using rbenv, or you can try the manual methods below.

Manual

From your terminal, clone the repository where you want it. From there, you have a couple of installation options.

git clone https://github.com/evanthegrayt/spoonerize.git
cd spoonerize

# Use rake to build and install the gem.
rake install

# OR manually link the executable somewhere. If you use this method, you cannot
# move the repository after you link it!
ln -s $PWD/bin/spoonerize /usr/local/bin/spoonerize

Command Line Usage

Call the executable and pass a phrase as arguments:

$ spoonerize not too shabby # => tot shoo nabby

If it didn't flip the way you wanted it to, you can reverse it:

$ spoonerize -r not too shabby # => shot noo tabby

If you find a phrase funny enough to save, you can pass the -s flag. This will write the results to the logfile. You can print your log file with the -p flag. It will show the original phrase, the end result, and the options used to get the results. For example:

$ spoonerize -s not too shabby
Saving [tot shoo nabby] to ~/.cache/spoonerize/spoonerize.csv

$ spoonerize -rs not too shabby
Saving [shot noo tabby] to ~/.cache/spoonerize/spoonerize.csv

$ spoonerize -p
not too shabby | tot shoo nabby | No Options
not too shabby | shot noo tabby | Reverse

Here is a list of all available options:

-r, --[no-]reverse               Reverse flipping
-l, --[no-]lazy                  Skip small words
-m, --[no-]map                   Print words mapping
-p, --[no-]print                 Print all entries in the log
-s, --[no-]save                  Save results in log
    --exclude=WORDS              Words to skip

Config File

You can create a config file called ~/.spoonerize.yml. In this file, you can change default options at runtime. Available settings are:

# Setting       Default
excluded_words: []
lazy:           false
reverse:        false
logfile_name:   '~/.cache/spoonerize/spoonerize.csv'

Options set by this file can be overridden at runtime by the use of the executable's flags.

API

The API is fully documented, but below are some quick examples of how you could use this in your ruby code.

require 'spoonerize'

spoonerism = Spoonerize::Spoonerism.new(%w[not too shabby]) do |s|
  s.reverse = true
end

spoonerism.spoonerize
# => shot noo tabby

spoonerism.reverse = false
spoonerism.spoonerize
# => tot shoo nabby

spoonerism.logfile_name = '~/.cache/spoonerize/spoonerize.csv'
spoonerism.save

You can also use the config file, either by passing it at initialization, or via the setter. The config file will be automatically loaded if passed at initialization, before the instance is yielded so you can still change the values via the block. If set via the setter, you must call #load_config_file.

# Config file would be automatically loaded before block is executed.
s = Spoonerise::Spoonerism.new(%w[not too shabby], '~/.spoonerize.yml') do |sp|
  sp.reverse = true
end

# Config file would need to be manually loaded.
s = Spoonerise::Spoonerism.new(%w[not too shabby]) do |sp|
  sp.config_file = '~/.spoonerize.yml'
end

s.load_config_file

Self Promotion

I do these projects for fun, and I enjoy knowing that they're helpful to people. Consider starring the repository if you like it! If you love it, follow me on github!

spoonerize's People

Contributors

dependabot[bot] avatar evanthegrayt avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

spoonerize's Issues

Make Cli class

We need to be able to test our command line interface. Make a Spoonerise::Cli class.

Log changes

If we're going to make this into a gem, the log directory won't be accessible by the user. We need to get a log reader going and implement it into the executable.

Don't raise if not enough flippable words

Because the options can change after the class is instantiated, we shouldn't raise if there aren't enough flippable words. This should be moved to the #spoonerise method.

Update tests

The tests are out of date since the major refactor. They work, but more tests are necessary for the new features.

Change config file

The config file should be redone as an initializer, rails style. I'm trying to use this in a rails app and I'd like to be able to do the following:

Spoonerize.configure do |c|
  c.excluded_words = %w[list of words]
  c.lazy = true
end

Add Rdoc

Add documentation to source code. Host the documentation on GitHub Pages

Change log file location

Currently, the log file gets lost every time the gem is updated. Keep the log file in ~/.cache/spoonerize/

regex lookahead for "y"

"This is my test" fails because 'Y' is only considered a consonant, so "m" and "y" stay together.

Update readme

The readme is out of date, especially the part about logging.

Update initialization

Change from:

def initialize(words, config_file = nil)
  # ...
end

to

def initialize(*words, config_file: nil)
  # ...
end

Not 100% sold on the *words; I could see how it could be useful to pass an array. Also, would definitely be useful to pass a string too.

Switch to test-unit

I've been preferring test-unit lately, so switch to that instead of rspec.

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.