Class: ValidatesCurp::Curp

Inherits:
Object
  • Object
show all
Defined in:
lib/validates_curp/curp.rb

Constant Summary collapse

REGEX =
/\A([A-Z][AEIOUX][A-Z]{2})([0-9]{2}[0-1][0-9][0-3][0-9])([MHX])([A-Z]{2})([BCDFGHJKLMNÑPQRSTVWXYZ]{3})([0-9A-Z][0-9])\z/i.freeze
VALID_STATES =
%w[AG BN BS CH CI CL CP CS DF DG GE GJ HD JA MC MR MX NA NL OA PU QE QI SI SL SO TA TB TL VC YU ZA NE].freeze

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Curp

Returns a new instance of Curp.



8
9
10
# File 'lib/validates_curp/curp.rb', line 8

def initialize(value)
  @value = value
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/validates_curp/curp.rb', line 12

def valid?
  return true if @value.blank?

  @value.match(REGEX)

  Regexp.last_match(0).present? && valid_date?(Regexp.last_match(2)) && valid_state?(Regexp.last_match(4))
end