No release in over 3 years
Low commit activity in last 3 years
Validates periods between two date ranges
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.0, < 5.3
 Project Readme

periods_validator

Build Status

Gem used to validate periods between a range of dates.

The periods allowed are the following:

  • monthly
  • quarterly
  • semesterly
  • yearly

These periods start from the first day of the month corresponding to the first date, until the last day of the month which corresponds to the last date.

For now, the models in which this validation is used must have the fields:

  • start_range
  • end_range

Installation

Add this line to your application's Gemfile:

gem 'periods_validator'

Examples

class Model < ApplicationRecord
	validates :start_range, presence: true, periods: %i[monthly yearly]
	validates :end_range, presence: true
end

Errors

The validator can return different errors depending on the data entered or the periods indicated by the developer.

There are several:

  • invalid_define_period: It occurs when the developer has not indicated a period allowed by the validator. For example:
validates :start_range, periods: %i[ other_period ]
# ---- or ----
validates :start_range, periods: %i[]
  • invalid_period: It occurs when the date of start_range or end_range are not filled or when the range formed by both dates does not match any required period. For example:
validates :start_range, periods: %i[ monthly ]
# start_range -> 01/01/2015
# end_range -> 01/12/2015 / or nil