From 43469ce48497784e9979886abb1d711786742226 Mon Sep 17 00:00:00 2001 From: mwlang Date: Sun, 16 Apr 2017 22:42:59 -0500 Subject: [PATCH] handle case of specifying times without specifying dates --- lib/nickel/construct_interpreter.rb | 14 ++++++++++++++ spec/lib/nickel_spec.rb | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/nickel/construct_interpreter.rb b/lib/nickel/construct_interpreter.rb index 8836c5b..e19a0d0 100644 --- a/lib/nickel/construct_interpreter.rb +++ b/lib/nickel/construct_interpreter.rb @@ -25,6 +25,8 @@ def run occurrences_from_recurrences_and_optional_date_span elsif found_wrappers_only occurrences_from_wrappers_only + elsif found_times + occurrences_from_times end end @@ -243,6 +245,12 @@ def found_dates @dci.size > 0 && @dsci.size == 0 && @rci.size == 0 end + def found_times + # One or more time constructs, NO date spans, NO recurrence, + # possible wrappers, possible time constructs, possible time spans + @tci.size > 0 && @dci.size == 0 && @dsci.size == 0 && @rci.size == 0 + end + def occurrences_from_dates @dci.each do |dindex| occ_base = Occurrence.new(type: :single, start_date: @constructs[dindex].date) @@ -250,6 +258,12 @@ def occurrences_from_dates end end + def occurrences_from_times + @tci.each do |index| + @occurrences << Occurrence.new(type: :single, start_time: @constructs[index].time) + end + end + def found_one_date_span @dci.size == 0 && @dsci.size == 1 && @rci.size == 0 end diff --git a/spec/lib/nickel_spec.rb b/spec/lib/nickel_spec.rb index 8ccf6fd..9cdecdd 100644 --- a/spec/lib/nickel_spec.rb +++ b/spec/lib/nickel_spec.rb @@ -28,6 +28,25 @@ end end + context "when the query is 'Yes, I can play at 9am'" do + let(:query) { 'Yes, I can play at 9am' } + let(:run_date) { Time.local(2014, 2, 26) } + + describe '#message' do + it "is 'yes I can play'" do + expect(n.message).to eq 'yes I can play' + end + end + + describe '#occurrences' do + it 'is single at 9:00am on unspecified date' do + expect(n.occurrences).to match_array [ + Nickel::Occurrence.new(type: :single, start_time: Nickel::ZTime.new('9')) + ] + end + end + end + context "when the query is 'wake up everyday at 11am'" do let(:query) { 'wake up everyday at 11am' } let(:run_date) { Time.local(2014, 2, 26) }