Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmcf committed Mar 4, 2021
1 parent 0f32f6f commit 37b49ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
16 changes: 9 additions & 7 deletions lib/business/calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ def self.load(calendar_name)
end

new(
calendar_name,
**data.slice("holidays", "working_days", "extra_working_days"),
name: calendar_name,
holidays: data["holidays"],
working_days: data["working_days"],
extra_working_dates: data["extra_working_days"],
)
end

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

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

attr_reader :name, :holidays, :working_days, :extra_working_dates
attr_reader :name,:holidays, :working_days, :extra_working_dates

def initialize(name, config)
def initialize(name:, extra_working_dates: nil, working_days: nil, holidays: nil)
@name = name
set_extra_working_dates(config[:extra_working_dates])
set_working_days(config[:working_days])
set_holidays(config[:holidays])
set_extra_working_dates(extra_working_dates)
set_working_days(working_days)
set_holidays(holidays)

unless (@holidays & @extra_working_dates).none?
raise ArgumentError, "Holidays cannot be extra working dates"
Expand Down
30 changes: 15 additions & 15 deletions spec/business/calendar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
describe "#set_working_days" do
subject(:set_working_days) { calendar.set_working_days(working_days) }

let(:calendar) { described_class.new("test", {}) }
let(:calendar) { described_class.new(name: "test") }
let(:working_days) { [] }

context "when given valid working days" do
Expand Down Expand Up @@ -123,7 +123,7 @@
describe "#set_holidays" do
subject(:holidays) { calendar.holidays }

let(:calendar) { described_class.new("test", {}) }
let(:calendar) { described_class.new(name: "test") }
let(:holiday_dates) { [] }

before { calendar.set_holidays(holiday_dates) }
Expand All @@ -148,7 +148,7 @@
describe "#set_extra_working_dates" do
subject(:extra_working_dates) { calendar.extra_working_dates }

let(:calendar) { described_class.new("test", {}) }
let(:calendar) { described_class.new(name: "test") }
let(:extra_dates) { [] }

before { calendar.set_extra_working_dates(extra_dates) }
Expand All @@ -172,7 +172,7 @@

context "when holiday is also a working date" do
let(:instance) do
described_class.new("test",
described_class.new(name: "test",
holidays: ["2018-01-06"],
extra_working_dates: ["2018-01-06"])
end
Expand All @@ -185,7 +185,7 @@

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

let(:calendar) do
described_class.new("test",
described_class.new(name: "test",
holidays: ["9am, Tuesday 1st Jan, 2013"],
extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
end
Expand Down Expand Up @@ -238,7 +238,7 @@
subject { calendar.working_day?(day) }

let(:calendar) do
described_class.new("test",
described_class.new(name: "test",
holidays: ["9am, Tuesday 1st Jan, 2013"],
extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
end
Expand Down Expand Up @@ -272,7 +272,7 @@
subject { calendar.holiday?(day) }

let(:calendar) do
described_class.new("test",
described_class.new(name: "test",
holidays: ["9am, Tuesday 1st Jan, 2013"],
extra_working_dates: ["9am, Sunday 6th Jan, 2013"])
end
Expand Down Expand Up @@ -306,7 +306,7 @@
subject { calendar.roll_forward(date) }

let(:calendar) do
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
end

context "given a business day" do
Expand Down Expand Up @@ -334,7 +334,7 @@
subject { calendar.roll_backward(date) }

let(:calendar) do
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
end

context "given a business day" do
Expand Down Expand Up @@ -362,7 +362,7 @@
subject { calendar.next_business_day(date) }

let(:calendar) do
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
end

context "given a business day" do
Expand Down Expand Up @@ -390,7 +390,7 @@
subject { calendar.previous_business_day(date) }

let(:calendar) do
described_class.new("test", holidays: ["Tuesday 1st Jan, 2013"])
described_class.new(name: "test", holidays: ["Tuesday 1st Jan, 2013"])
end

context "given a business day" do
Expand Down Expand Up @@ -419,7 +419,7 @@

let(:extra_working_dates) { [] }
let(:calendar) do
described_class.new("test",
described_class.new(name: "test",
holidays: ["Tuesday 1st Jan, 2013"],
extra_working_dates: extra_working_dates)
end
Expand Down Expand Up @@ -464,7 +464,7 @@

let(:extra_working_dates) { [] }
let(:calendar) do
described_class.new("test",
described_class.new(name: "test",
holidays: ["Thursday 3rd Jan, 2013"],
extra_working_dates: extra_working_dates)
end
Expand Down Expand Up @@ -518,7 +518,7 @@
["Sun 1/6/2014", "Sat 28/6/2014", "Sat 5/7/2014"]
end
let(:calendar) do
described_class.new("test",
described_class.new(name: "test",
holidays: holidays,
extra_working_dates: extra_working_dates)
end
Expand Down

0 comments on commit 37b49ce

Please sign in to comment.