From 3082fabcb9370c99c5bf6af0a235fde6298070b5 Mon Sep 17 00:00:00 2001 From: Deepak Bhimaraju Date: Tue, 31 May 2016 10:11:39 -0400 Subject: [PATCH] Completed Parser Challenge --- parser.rb | 8 +++++++- word_in_string_spec.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/parser.rb b/parser.rb index adaad3e..2093d59 100644 --- a/parser.rb +++ b/parser.rb @@ -1,3 +1,9 @@ def word_in_string?(word, string) - # implement with your code here + regex = /(\A|\W|[_])#{word}(\W|\z|[_])/ + + if(regex =~ string) + :yes + else + :no + end end diff --git a/word_in_string_spec.rb b/word_in_string_spec.rb index 43c801f..2920d81 100644 --- a/word_in_string_spec.rb +++ b/word_in_string_spec.rb @@ -3,6 +3,7 @@ require 'pry' describe "word_in_string?" do + context "returns symbols :yes and :no" do it "should return :no for word_in_string?('grow', 'growler')" do expect(word_in_string?('grow', 'growler')).to eq :no