class IsWord

IsWord v1.0 test word existence

Constants

RESOURCE_DIR

Word validating class

Public Class Methods

new() click to toggle source
# File lib/isword.rb, line 10
def initialize()

    # Load dictionary

    @words = {}

    begin

        IO.foreach( RESOURCE_DIR + "/dictionary.txt" ) { |word|
            @words[ word.strip ] = true
        }

    rescue SystemCallError
        # In case of missing resource
        raise IOError.new( "dictoinary.txt resource not found in gem directory" )
    end

end

Public Instance Methods

is?( word ) click to toggle source
# File lib/isword.rb, line 29
def is?( word )

    # Check for word validity

    begin

        return @words[ word.downcase ]

    rescue NoMethodError
        # For invalid types
        raise TypeError.new( "word must be of type String" )
    end

end