Skip to content

Commit 37b49ce

Browse files
committed
pr feedback
1 parent 0f32f6f commit 37b49ce

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

lib/business/calendar.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ def self.load(calendar_name)
2525
end
2626

2727
new(
28-
calendar_name,
29-
**data.slice("holidays", "working_days", "extra_working_days"),
28+
name: calendar_name,
29+
holidays: data["holidays"],
30+
working_days: data["working_days"],
31+
extra_working_dates: data["extra_working_days"],
3032
)
3133
end
3234

@@ -53,13 +55,13 @@ def self.load_cached(calendar)
5355

5456
DAY_NAMES = %( mon tue wed thu fri sat sun )
5557

56-
attr_reader :name, :holidays, :working_days, :extra_working_dates
58+
attr_reader :name,:holidays, :working_days, :extra_working_dates
5759

58-
def initialize(name, config)
60+
def initialize(name:, extra_working_dates: nil, working_days: nil, holidays: nil)
5961
@name = name
60-
set_extra_working_dates(config[:extra_working_dates])
61-
set_working_days(config[:working_days])
62-
set_holidays(config[:holidays])
62+
set_extra_working_dates(extra_working_dates)
63+
set_working_days(working_days)
64+
set_holidays(holidays)
6365

6466
unless (@holidays & @extra_working_dates).none?
6567
raise ArgumentError, "Holidays cannot be extra working dates"

spec/business/calendar_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
describe "#set_working_days" do
8585
subject(:set_working_days) { calendar.set_working_days(working_days) }
8686

87-
let(:calendar) { described_class.new("test", {}) }
87+
let(:calendar) { described_class.new(name: "test") }
8888
let(:working_days) { [] }
8989

9090
context "when given valid working days" do
@@ -123,7 +123,7 @@
123123
describe "#set_holidays" do
124124
subject(:holidays) { calendar.holidays }
125125

126-
let(:calendar) { described_class.new("test", {}) }
126+
let(:calendar) { described_class.new(name: "test") }
127127
let(:holiday_dates) { [] }
128128

129129
before { calendar.set_holidays(holiday_dates) }
@@ -148,7 +148,7 @@
148148
describe "#set_extra_working_dates" do
149149
subject(:extra_working_dates) { calendar.extra_working_dates }
150150

151-
let(:calendar) { described_class.new("test", {}) }
151+
let(:calendar) { described_class.new(name: "test") }
152152
let(:extra_dates) { [] }
153153

154154
before { calendar.set_extra_working_dates(extra_dates) }
@@ -172,7 +172,7 @@
172172

173173
context "when holiday is also a working date" do
174174
let(:instance) do
175-
described_class.new("test",
175+
described_class.new(name: "test",
176176
holidays: ["2018-01-06"],
177177
extra_working_dates: ["2018-01-06"])
178178
end
@@ -185,7 +185,7 @@
185185

186186
context "when working date on working day" do
187187
let(:instance) do
188-
described_class.new("test",
188+
described_class.new(name: "test",
189189
working_days: ["mon"],
190190
extra_working_dates: ["Monday 26th Mar, 2018"])
191191
end
@@ -204,7 +204,7 @@
204204
subject { calendar.business_day?(day) }
205205

206206
let(:calendar) do
207-
described_class.new("test",
207+
described_class.new(name: "test",
208208
holidays: ["9am, Tuesday 1st Jan, 2013"],
209209
extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
210210
end
@@ -238,7 +238,7 @@
238238
subject { calendar.working_day?(day) }
239239

240240
let(:calendar) do
241-
described_class.new("test",
241+
described_class.new(name: "test",
242242
holidays: ["9am, Tuesday 1st Jan, 2013"],
243243
extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
244244
end
@@ -272,7 +272,7 @@
272272
subject { calendar.holiday?(day) }
273273

274274
let(:calendar) do
275-
described_class.new("test",
275+
described_class.new(name: "test",
276276
holidays: ["9am, Tuesday 1st Jan, 2013"],
277277
extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
278278
end
@@ -306,7 +306,7 @@
306306
subject { calendar.roll_forward(date) }
307307

308308
let(:calendar) do
309-
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
309+
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
310310
end
311311

312312
context "given a business day" do
@@ -334,7 +334,7 @@
334334
subject { calendar.roll_backward(date) }
335335

336336
let(:calendar) do
337-
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
337+
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
338338
end
339339

340340
context "given a business day" do
@@ -362,7 +362,7 @@
362362
subject { calendar.next_business_day(date) }
363363

364364
let(:calendar) do
365-
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
365+
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
366366
end
367367

368368
context "given a business day" do
@@ -390,7 +390,7 @@
390390
subject { calendar.previous_business_day(date) }
391391

392392
let(:calendar) do
393-
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
393+
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
394394
end
395395

396396
context "given a business day" do
@@ -419,7 +419,7 @@
419419

420420
let(:extra_working_dates) { [] }
421421
let(:calendar) do
422-
described_class.new("test",
422+
described_class.new(name: "test",
423423
holidays: ["Tuesday 1st Jan, 2013"],
424424
extra_working_dates: extra_working_dates)
425425
end
@@ -464,7 +464,7 @@
464464

465465
let(:extra_working_dates) { [] }
466466
let(:calendar) do
467-
described_class.new("test",
467+
described_class.new(name: "test",
468468
holidays: ["Thursday 3rd Jan, 2013"],
469469
extra_working_dates: extra_working_dates)
470470
end
@@ -518,7 +518,7 @@
518518
["Sun 1/6/2014", "Sat 28/6/2014", "Sat 5/7/2014"]
519519
end
520520
let(:calendar) do
521-
described_class.new("test",
521+
described_class.new(name: "test",
522522
holidays: holidays,
523523
extra_working_dates: extra_working_dates)
524524
end

0 commit comments

Comments
 (0)