BlackFriday
Add Black Friday sales to your Rails app.
Installation
Install the gem and add to the application's Gemfile by executing:
bundle add black_fridayUsage
Date helpers
Black Friday provides some helpers for dates. You can also pass in the year which can be helpful for making reports for previous years.
BlackFriday.thanksgiving #=> Thu, 28 Nov 2024
BlackFriday.black_friday #=> Fri, 29 Nov 2024
BlackFriday.cyber_monday #=> Mon, 2 Dec 2024
BlackFriday.thanksgiving(2029) #=> Thu, 22 Nov 2029Adding Sales
Sales are handy to set the date/time range for a sale. The add_sale block should return a Range.
BlackFriday.add_sale do
thanksgiving.monday.beginning_of_day..cyber_monday.end_of_day
end
BlackFriday.add_sale :labor_day do
# First Monday in September
sep_1st = Date.new(Date.today.year, 9, 1)
labor_day = sep_1st.monday? ? sep_1st : sep_1st.next_occurring(:monday)
start_day = labor_day - 3.days
start_day.beginning_of_day..labor_day.end_of_day
endYou can then check if a sale is active:
BlackFriday.active?
#=> true/false
# Or specific sale(s)
BlackFriday.active?(:black_friday, :labor_day)
#=> true/falseRender a banner when a sale is active:
<%= render "banners/black_friday" if BlackFriday.active?(:black_friday) %>To check the active sales:
BlackFriday.current_sale #=> :black_friday
# For multiple sales at once
BlackFriday.current_sales #=> [:black_friday]Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/excid3/black_friday. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the BlackFriday project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.