diff --git a/README.md b/README.md index d368d8a..9eb48ac 100644 --- a/README.md +++ b/README.md @@ -52,10 +52,13 @@ gem "business", "~> 2.0" Get started with business by creating an instance of the calendar class, that accepts a hash that specifies which days of the week are considered working days, which days are holidays and which are extra working dates. +Additionally each calendar instance can be given a name. This can come in handy if you use multiple calendars. + ```ruby calendar = Business::Calendar.new( + name: 'my calendar', working_days: %w( mon tue wed thu fri ), - holidays: ["01/01/2014", "03/01/2014"] # array items are either parseable date strings, or real Date objects + holidays: ["01/01/2014", "03/01/2014"], # array items are either parseable date strings, or real Date objects extra_working_dates: [nil], # Makes the calendar to consider a weekend day as a working day. ) ``` diff --git a/lib/business/calendar.rb b/lib/business/calendar.rb index be861e8..6e2a70f 100644 --- a/lib/business/calendar.rb +++ b/lib/business/calendar.rb @@ -59,7 +59,7 @@ def self.load_cached(calendar) attr_reader :name, :holidays, :working_days, :extra_working_dates - def initialize(name:, extra_working_dates: nil, working_days: nil, holidays: nil) + def initialize(name: nil, extra_working_dates: nil, working_days: nil, holidays: nil) @name = name set_extra_working_dates(extra_working_dates) set_working_days(working_days) diff --git a/spec/business/calendar_spec.rb b/spec/business/calendar_spec.rb index c2a8bd3..f79db71 100644 --- a/spec/business/calendar_spec.rb +++ b/spec/business/calendar_spec.rb @@ -81,6 +81,18 @@ end end + describe ".new" do + it "allows to skip a name" do + instance = described_class.new + expect(instance.name).to eq nil + end + + it "allows to set a name" do + instance = described_class.new(name: "foo") + expect(instance.name).to eq "foo" + end + end + describe "#set_working_days" do subject(:set_working_days) { calendar.set_working_days(working_days) }