Created
February 11, 2015 05:57
-
-
Save jdecuirm/48d4ded20e50318bfd88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loaded suite /home/jdecuirm/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/rake/rake_test_loader | |
Started | |
.F | |
=============================================================================== | |
Failure: | |
test_errors(TestName) | |
/home/jdecuirm/Documents/Ruby_Development/RTHW/projects/ex48/tests/test_lexicon.rb:37:in `test_errors' | |
34: end | |
35: | |
36: def test_errors() | |
=> 37: assert_equal(Lexicon.scan('ASDFAADSD'),[['error','ASDFAADSD']]) | |
38: result = Lexicon.scan("bear IAS princess") | |
39: assert_equal(result,[['noun','bear'],['error','IAS'],['noun','princess']]) | |
40: end | |
<[["number", 0]]> expected but was | |
<[["error", "ASDFAADSD"]]> | |
diff: | |
? [["numbe r", 0 ]] | |
? rro "ASDFAADSD" | |
=============================================================================== | |
.... | |
Finished in 0.006085096 seconds. | |
6 tests, 11 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
83.3333% passed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Lexicon | |
#Arrays that holds the words to compare | |
@directions = %w{south west east north} | |
@verbs = %w{go kill eat play say talk jump fight throw smile hit punch climb move} | |
@nouns = %w{bear princess penguin mole cherry lollipop pillow} | |
@stop_words = %w{the in of} | |
#Class method that gets a string and classify the word. It makes an array of the classification and the word | |
def self.scan(inputed_text) | |
defined_array_words = [] | |
words = inputed_text.split(" ") | |
words.each do |word| | |
if @directions.include?(word) | |
defined_array_words << ['direction',word] | |
elsif @verbs.include?(word) | |
defined_array_words << ['verb',word] | |
elsif @nouns.include?(word) | |
defined_array_words << ['noun',word] | |
elsif @stop_words.include?(word) | |
defined_array_words << ['stop',word] | |
elsif word.to_i.is_a?(Integer) | |
defined_array_words << ['number',word.to_i] | |
else | |
defined_array_words << ['error',word] | |
end | |
end | |
defined_array_words | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment