Module: WordFinder

Defined in:
lib/word_finder/node.rb,
lib/word_finder.rb,
lib/word_finder/checker.rb,
lib/word_finder/version.rb

Overview

WordFinder. Copyright © 2012 Chris Corbyn.

See LICENSE file for details.

Defined Under Namespace

Classes: Checker, Node

Constant Summary collapse

VERSION =
"0.0.2"

Class Method Summary collapse

Class Method Details

.words_in(phrase, options = {}) ⇒ Array<String>

Find all the words in the given phrase, ignoring unrecognized characters.

Words will be accumulated to use the longest possible matches.

Parameters:

  • phrase (String)

    a sentence, which need not contain whitespace or punctuation

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Array<String>)

    an Array containing all words found, in order



26
27
28
29
30
# File 'lib/word_finder.rb', line 26

def words_in(phrase, options = {})
  Node.new(options).tap{|node|
    phrase.each_char(&node.method(:insert))
  }.words.reject{|m| m !~ /\w/}
end