Skip to content

Commit 2b96640

Browse files
authored
Merge pull request #83 from ineu/make-name-optional
Make name optional
2 parents fc9d4b8 + 2d06a66 commit 2b96640

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ gem "business", "~> 2.0"
5252

5353
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.
5454

55+
Additionally each calendar instance can be given a name. This can come in handy if you use multiple calendars.
56+
5557
```ruby
5658
calendar = Business::Calendar.new(
59+
name: 'my calendar',
5760
working_days: %w( mon tue wed thu fri ),
58-
holidays: ["01/01/2014", "03/01/2014"] # array items are either parseable date strings, or real Date objects
61+
holidays: ["01/01/2014", "03/01/2014"], # array items are either parseable date strings, or real Date objects
5962
extra_working_dates: [nil], # Makes the calendar to consider a weekend day as a working day.
6063
)
6164
```

lib/business/calendar.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def self.load_cached(calendar)
5959

6060
attr_reader :name, :holidays, :working_days, :extra_working_dates
6161

62-
def initialize(name:, extra_working_dates: nil, working_days: nil, holidays: nil)
62+
def initialize(name: nil, extra_working_dates: nil, working_days: nil, holidays: nil)
6363
@name = name
6464
set_extra_working_dates(extra_working_dates)
6565
set_working_days(working_days)

spec/business/calendar_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@
8181
end
8282
end
8383

84+
describe ".new" do
85+
it "allows to skip a name" do
86+
instance = described_class.new
87+
expect(instance.name).to eq nil
88+
end
89+
90+
it "allows to set a name" do
91+
instance = described_class.new(name: "foo")
92+
expect(instance.name).to eq "foo"
93+
end
94+
end
95+
8496
describe "#set_working_days" do
8597
subject(:set_working_days) { calendar.set_working_days(working_days) }
8698

0 commit comments

Comments
 (0)