Class: Uy::Rut
- Inherits:
-
Object
- Object
- Uy::Rut
- Defined in:
- lib/uy/rut.rb
Constant Summary collapse
- FACTORS =
[4,3,2,9,8,7,6,5,4,3,2]
Instance Attribute Summary collapse
-
#rut ⇒ Object
Returns the value of attribute rut.
Instance Method Summary collapse
-
#initialize(rut = nil) ⇒ Rut
constructor
A new instance of Rut.
- #is_valid? ⇒ Boolean (also: #valid?)
Constructor Details
Instance Attribute Details
#rut ⇒ Object
Returns the value of attribute rut.
5 6 7 |
# File 'lib/uy/rut.rb', line 5 def rut @rut end |
Instance Method Details
#is_valid? ⇒ Boolean Also known as: valid?
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/uy/rut.rb', line 11 def is_valid? return false unless @rut =~ /\d{12}/ return false unless (1..21) === @rut[0..1].to_i (2..7).each {|pos| return false unless (1..9) === @rut[pos].to_i} return false unless @rut[8..9] == '00' begin return false unless Rut.calculate_check_digit(@rut) == @rut[11].to_i rescue return false end true end |