Skip to content

Commit

Permalink
Merge pull request #83 from ineu/make-name-optional
Browse files Browse the repository at this point in the history
Make name optional
  • Loading branch information
JoeSouthan authored Mar 9, 2021
2 parents fc9d4b8 + 2d06a66 commit 2b96640
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
)
```
Expand Down
2 changes: 1 addition & 1 deletion lib/business/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions spec/business/calendar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down

0 comments on commit 2b96640

Please sign in to comment.