-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9682b72
commit 3b14392
Showing
5 changed files
with
89 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Value object - date range | ||
class DateRange < ValueObject | ||
attr_reader :start_date, :end_date | ||
|
||
def initialize(start_date:, end_date:) | ||
# rubocop:disable Lint/MissingSuper | ||
@start_date = start_date.beginning_of_day | ||
@end_date = end_date.end_of_day | ||
end | ||
|
||
def to_s | ||
"from #{start_date.to_fs(:short)} to #{end_date.to_fs(:short)}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Value object - date range | ||
class Location < ValueObject | ||
attr_accessor :state, :street_location, :city, :zipcode | ||
|
||
def initialize(state:, street_location: nil, city: nil, zipcode: nil) # rubocop:disable Lint/MissingSuper | ||
@state = state | ||
@street_location = street_location | ||
@city = city | ||
@zipcode = zipcode | ||
end | ||
|
||
def to_s(letter_style: false) | ||
if letter_style | ||
"#{street_location}\n#{city}, #{state} #{zipcode}" | ||
else | ||
[street_location, city, state, zipcode].compact.join(', ') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe DateRange do | ||
it 'should return a string representing the date object' do | ||
start_date = 5.days.ago.beginning_of_day | ||
end_date = 2.days.ago.end_of_day | ||
date = DateRange.new(start_date: start_date, end_date: end_date) | ||
puts "Start date #{start_date}" | ||
expect(date.to_s).to eq "from #{start_date.to_fs(:short)} to #{end_date.to_fs(:short)}" | ||
end | ||
|
||
it 'should mark date ranges with the same dates as equal' do | ||
date_one = DateRange.new(start_date: 5.days.ago, end_date: 2.days.ago) | ||
date_two = DateRange.new(start_date: 5.days.ago, end_date: 2.days.ago) | ||
expect(date_one == date_two).to be_truthy | ||
end | ||
end |