Skip to content

Commit

Permalink
initial value object and date range
Browse files Browse the repository at this point in the history
  • Loading branch information
mnyon-grandkru committed Feb 26, 2024
1 parent 9682b72 commit 3b14392
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 37 deletions.
3 changes: 0 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ gem 'redis', '>= 4.0.1'
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
# gem "bcrypt", "~> 3.1.7"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: %i[windows jruby]

# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', require: false

Expand Down
67 changes: 33 additions & 34 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ GEM
bindex (0.8.1)
bootsnap (1.17.0)
msgpack (~> 1.2)
brakeman (6.0.1)
brakeman (6.1.0)
builder (3.2.4)
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
Expand All @@ -102,34 +102,34 @@ GEM
crack (0.4.5)
rexml
crass (1.0.6)
cucumber (9.0.2)
cucumber (9.1.0)
builder (~> 3.2, >= 3.2.4)
cucumber-ci-environment (~> 9.2, >= 9.2.0)
cucumber-core (~> 11.1, >= 11.1.0)
cucumber-cucumber-expressions (~> 16.1, >= 16.1.2)
cucumber-gherkin (>= 24, < 26.2.1)
cucumber-core (~> 12.0)
cucumber-cucumber-expressions (~> 17.0)
cucumber-gherkin (>= 24, < 27)
cucumber-html-formatter (~> 20.4, >= 20.4.0)
cucumber-messages (>= 19, < 23)
diff-lcs (~> 1.5, >= 1.5.0)
mini_mime (~> 1.1, >= 1.1.5)
multi_test (~> 1.1, >= 1.1.0)
sys-uname (~> 1.2, >= 1.2.3)
cucumber-ci-environment (9.2.0)
cucumber-core (11.1.0)
cucumber-gherkin (>= 24, < 27)
cucumber-messages (>= 19, < 22)
cucumber-tag-expressions (~> 4.1, >= 4.1.0)
cucumber-cucumber-expressions (16.1.2)
cucumber-core (12.0.0)
cucumber-gherkin (>= 25, < 27)
cucumber-messages (>= 20, < 23)
cucumber-tag-expressions (~> 5.0, >= 5.0.4)
cucumber-cucumber-expressions (17.0.1)
cucumber-gherkin (26.2.0)
cucumber-messages (>= 19.1.4, < 22.1)
cucumber-html-formatter (20.4.0)
cucumber-messages (>= 18.0, < 22.1)
cucumber-messages (21.0.1)
cucumber-messages (22.0.0)
cucumber-rails (3.0.0)
capybara (>= 3.11, < 4)
cucumber (>= 5, < 10)
railties (>= 5.2, < 8)
cucumber-tag-expressions (4.1.0)
cucumber-tag-expressions (5.0.6)
database_cleaner-active_record (2.1.0)
activerecord (>= 5.a)
database_cleaner-core (~> 2.0.0)
Expand All @@ -142,10 +142,10 @@ GEM
drb (2.2.0)
ruby2_keywords
erubi (1.12.0)
factory_bot (6.2.1)
factory_bot (6.4.2)
activesupport (>= 5.0.0)
factory_bot_rails (6.2.0)
factory_bot (~> 6.2.0)
factory_bot_rails (6.4.2)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.2.2)
i18n (>= 1.8.11, < 2)
Expand All @@ -160,17 +160,17 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.6.0)
irb (1.9.0)
irb (1.10.1)
rdoc
reline (>= 0.3.8)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.6.3)
json (2.7.1)
language_server-protocol (3.17.0.3)
launchy (2.5.2)
addressable (~> 2.8)
loofah (2.21.4)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
Expand All @@ -182,11 +182,11 @@ GEM
matrix (0.4.2)
mini_mime (1.1.5)
minitest (5.20.0)
mock_redis (0.39.0)
mock_redis (0.40.0)
msgpack (1.7.2)
multi_test (1.1.0)
mutex_m (0.2.0)
net-imap (0.4.4)
net-imap (0.4.7)
date
net-protocol
net-pop (0.1.2)
Expand All @@ -195,8 +195,8 @@ GEM
timeout
net-smtp (0.4.0)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.4-x86_64-linux)
nio4r (2.7.0)
nokogiri (1.15.5-x86_64-linux)
racc (~> 1.4)
parallel (1.23.0)
parser (3.2.2.4)
Expand All @@ -205,7 +205,7 @@ GEM
pg (1.5.4)
psych (5.1.1.1)
stringio
public_suffix (5.0.3)
public_suffix (5.0.4)
puma (6.4.0)
nio4r (~> 2.0)
racc (1.7.3)
Expand Down Expand Up @@ -248,14 +248,14 @@ GEM
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.1.0)
rdoc (6.6.0)
rdoc (6.6.1)
psych (>= 4.0.0)
redis (5.0.8)
redis-client (>= 0.17.0)
redis-client (0.18.0)
redis-client (0.19.0)
connection_pool
regexp_parser (2.8.2)
reline (0.4.0)
regexp_parser (2.8.3)
reline (0.4.1)
io-console (~> 0.5)
rexml (3.2.6)
rspec-core (3.12.2)
Expand All @@ -266,7 +266,7 @@ GEM
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.0.3)
rspec-rails (6.1.0)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
Expand All @@ -275,22 +275,22 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.57.2)
rubocop (1.58.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
rubocop-discourse (3.4.0)
rubocop-discourse (3.4.1)
rubocop (>= 1.1.0)
rubocop-rspec (>= 2.0.0)
rubocop-factory_bot (2.24.0)
Expand All @@ -302,7 +302,7 @@ GEM
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
selenium-webdriver (4.15.0)
selenium-webdriver (4.16.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand All @@ -317,7 +317,7 @@ GEM
sprockets (>= 3.0.0)
stimulus-rails (1.3.0)
railties (>= 6.0.0)
stringio (3.0.9)
stringio (3.1.0)
sys-uname (1.2.3)
ffi (~> 1.1)
thor (1.3.0)
Expand Down Expand Up @@ -379,7 +379,6 @@ DEPENDENCIES
sprockets-rails
stimulus-rails
turbo-rails
tzinfo-data
vcr
web-console
webmock
Expand Down
16 changes: 16 additions & 0 deletions app/models/date_range.rb
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
21 changes: 21 additions & 0 deletions app/models/value_object.rb
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
19 changes: 19 additions & 0 deletions spec/models/date_range_spec.rb
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

0 comments on commit 3b14392

Please sign in to comment.