Skip to content

patrickcarver/random_word_service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RandomWordService

RandomWordService is an application that will return a random word given up to 2 parameters to the get_random_word function.

Usage

This is an Elixir application, so when this module is added as a dependency, the start_link function will be automatically be called to load up of the word lists of parts of speech.

get_random_word

Use the get_random_word function to get a random word. The function returns an :ok tuple with the word or an :error tuple if something is awry. (e.g. the starts_with parameter is a number).

The are up to two parameters that can be used:

  • starts_with: A string that the random word needs to start with. Only English letters are valid. Capitalization of the string does not matter.

  • part_of_speech: A string of the part of speech the word needs to be. Valid parts of speech are "adjective", "adverb", "noun", or "verb".

Both parameters do not need to be used. Using only starts_with will return an adjective, adverb, noun, or verb starting with the specified string. Using only part_of_speech will return a word starting with any letter that is the specified part of speech.

Also, get_random_word can be invoked without any parameters. It will randomly select a part of speech and the starting letter.

lists

There is a function called list that will return the struct of the parts of speech word lists.

Examples

iex(1)> RandomWordService.get_random_word(starts_with: "r", part_of_speech: "adjective")
{:ok, "resigned"}

iex(2)> RandomWordService.get_random_word(starts_with: "r")
{:ok, "repeatedly"}

iex(3)> RandomWordService.get_random_word(part_of_speech: "adjective")
{:ok, "relevant"}

iex(4)> RandomWordService.get_random_word()
{:ok, "all-out"}

iex(5)> RandomWordService.get_random_word(starts_with: "rat", part_of_speech: "adjective")
{:ok, "rational"}

iex(6)> RandomWordService.get_random_word(starts_with: "rrr", part_of_speech: "adjective")
{:error, "starts_with rrr not found"}

iex(7)> RandomWordService.get_random_word(stars_wth: "r", part_of_speech: "adjective")
{:error, "cannot use invalid options"}

iex(8)> RandomWordService.get_random_word(starts_with: "r", part_of_speech: :adjctiv)
{:error, "value is not in the list"}

iex(9)> RandomWordService.get_random_word(starts_with: 1, part_of_speech: :adjective)
{:error, "value must be a string"}

iex(10)> RandomWordService.get_random_word(starts_with: "10", part_of_speech: :adjective)
{:error, "value must contain only English alphabetic characters"}

Installation

The package can be installed by adding random_word_service to your list of dependencies in mix.exs:

def deps do
  [
    { :random_word_service,
      git: "https://github.com/patrickcarver/random_word_service.git", 
      tag: "v1.0.2" }
  ]
end

About

Elixir module to provide random words given part of speech and beginning letter

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages