Apalabrado.vb

  1. ' Apalabrado.vb — ProInf.net — 7-mar-2012
  2.  
  3. '================================================
  4. ' INTERFACE APALABRADO
  5.  
  6. Public Interface IApalabrado
  7. Sub Apalabrar(ByVal palabra As String, ByVal esFemenina As Boolean)
  8. End Interface
  9.  
  10. Public Class Apalabrado
  11. Implements IApalabrado
  12.  
  13. Private _palabraSingular As String
  14. Private _palabraPlural As String
  15. Private _femenina As Boolean
  16.  
  17. Public Sub Apalabrar(ByVal palabra As String, ByVal esFemenina As Boolean
  18. ) Implements IApalabrado.Apalabrar
  19. If palabra.Contains(";") Then
  20. Dim items = Split(palabra, ";")
  21. _palabraSingular = items(0)
  22. _palabraPlural = items(1)
  23. Else
  24. _palabraSingular = palabra
  25. _palabraPlural = EnPlural(palabra)
  26. End If
  27. _femenina = esFemenina
  28. End Sub
  29.  
  30. Public Function Obtener(ByVal enSingular As Boolean) As String
  31. If _palabraSingular = "" Then
  32. Return ""
  33. ElseIf enSingular Then
  34. Return " " & _palabraSingular
  35. Else
  36. Return " " & _palabraPlural
  37. End If
  38. End Function
  39.  
  40. Public Function EsFemenina() As Boolean
  41. Return _femenina
  42. End Function
  43.  
  44. Protected Shared Function EnPlural(ByVal texto As String) As String
  45. If texto = "" Then
  46. Return ""
  47. ElseIf AcabaEnVocal(texto) Then
  48. Return texto & "s"
  49. Else
  50. Return texto & "es"
  51. End If
  52. End Function
  53.  
  54. Public Shared Function AcabaEnVocal(ByVal texto As String) As String
  55. Return "aeiou".Contains(texto(texto.Length - 1))
  56. End Function
  57.  
  58. End Class
  59.  

Proinf.net