Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make name optional #83

Merged
merged 4 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it might be good to add the name arg here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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