Sha256: 7fa2c1a4c99f880089cbc687ed30cee94880da78653358172a60237eb46eb376

Contents?: true

Size: 869 Bytes

Versions: 1

Compression:

Stored size: 869 Bytes

Contents

# IsWord v1.0 test word existence

class IsWord

    # Word validating class

    RESOURCE_DIR  = File.expand_path( "../resources", File.dirname( __FILE__ ) )

    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

    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

end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
isword-0.0.1 lib/isword.rb