From 5b66e9049b42109ec15d1b43af98930aea3f178c Mon Sep 17 00:00:00 2001 From: Dzmitry Plashchynski Date: Thu, 5 Mar 2015 13:47:11 +0200 Subject: [PATCH] Add Period#description --- lib/crono/period.rb | 6 ++++++ spec/period_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lib/crono/period.rb b/lib/crono/period.rb index 5c9e172..378e071 100644 --- a/lib/crono/period.rb +++ b/lib/crono/period.rb @@ -10,6 +10,12 @@ module Crono @period.since(since).change({hour: @at_hour, min: @at_min}.compact) end + def description + desc = "every #{@period.inspect}" + desc += " at #{@at_hour}:#{@at_min}" if @at_hour && @at_min + desc + end + def parse_at(at) case at when String diff --git a/spec/period_spec.rb b/spec/period_spec.rb index 6057d88..29b5b92 100644 --- a/spec/period_spec.rb +++ b/spec/period_spec.rb @@ -7,6 +7,13 @@ describe Crono::Period do end end + describe "#description" do + it "should return period description" do + @period = Crono::Period.new(2.day, at: "15:20") + expect(@period.description).to be_eql("every 2 days at 15:20") + end + end + describe "#next" do context "in daily basis" do it "should return the time 2 days from now" do