Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
agregando validaciones de nota
- Loading branch information
unknown
authored and
unknown
committed
Apr 12, 2012
1 parent
771175d
commit 94d2f94
Showing
4 changed files
with
68 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
class Curso < ActiveRecord::Base | ||
|
||
validates_presence_of :nombre, :message => "Ingrese un nombre" | ||
validates_presence_of :formula, :message => "Ingrese la formula" | ||
validates_presence_of :nombre, :message => "no ha sido ingresado." | ||
validates_presence_of :formula, :message => "no ha sido ingresada." | ||
|
||
after_validation :validateFormula | ||
|
||
def validateFormula | ||
|
||
acumulado = 0 | ||
|
||
formulaPlus = self[:formula].split("+") | ||
|
||
for i in 0..formulaPlus.length-1 | ||
pesoXExam = formulaPlus[i].scan(/\d\d%[A-Z0-9]+/) | ||
if pesoXExam.length == 0 | ||
errors.add(:formula," es incorrecta.") | ||
return false | ||
end | ||
end | ||
|
||
pesos = self[:formula].scan(/\d\d/) | ||
for i in 0..pesos.length-1 | ||
acumulado = acumulado + pesos[i].to_i | ||
end | ||
|
||
if acumulado == 100 | ||
|
||
return true | ||
else | ||
errors.add(:formula," no llega al 100%.") | ||
|
||
# raise "ERROR PS MUY TARDE" | ||
return false | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters