Class: APA
- Inherits:
-
Object
- Object
- APA
- Defined in:
- lib/prct11/APA.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize ⇒ APA
constructor
A new instance of APA.
- #insert(reference) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ APA
Returns a new instance of APA.
27 28 29 30 |
# File 'lib/prct11/APA.rb', line 27 def initialize() @lista = LinkedList.new @sufijo = 0 end |
Instance Method Details
#each ⇒ Object
55 56 57 |
# File 'lib/prct11/APA.rb', line 55 def each @lista.each{ |i| yield i} end |
#insert(reference) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/prct11/APA.rb', line 32 def insert(reference) raise ArgumentError, "La referencia no es de tipo referencia" unless reference.kind_of?(Reference) # Renombramos los autores para ordenar bien str = "" reference..each do |a| # raise ArgumentError, "Uno de los autores no es un string" unless a.is_a?(String) # raise ArgumentError, "Se especifica unicamente el nombre o el apellido" unless a.split(' ').length > 1 element = a.split(/\W+/) str+=element[1] str+=", " unless element[2].nil? str+=element[2][0] str+="." end str+=element[0][0] str+="." str+=" & " unless a == reference..last end reference. = str @lista.insert_by_end(reference) end |
#to_s ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/prct11/APA.rb', line 59 def to_s = "" datePrev = "" listSort = @lista.sort string = "" listSort.each do |i| if (i.instance_of? Book) # Autores APA string += i. # Año de publicacion APA element = i.date.split(/\//) string += " (#{element[2]}" if (i.date == datePrev && i. == ) string += (@sufijo+97).chr string += "). " @sufijo += 1 else string += "). " end = i. datePrev = i.date # Título APA string += " #{i.title.capitalize} " # Edición APA string += " (#{i.edition}) " # Volumen APA string += " (#{i.volume}). " # Editorial APA string += " #{i.editorial} \n\n" elsif (i.class.to_s == "JournalArticle") # Autores APA string += i. # fecha de publicacion APA string += " (#{i.date}" if (i.date == datePrev && i. == ) string += (@sufijo+97).chr string += "). " @sufijo += 1 else string += "). " end = i. datePrev = i.date # Título articuloAPA string += " #{i.title.capitalize}. " # Nombre periodico APA string += " #{i.journal}, " # Número de paginas APA string += " #{i.finalpage}.\n\n " elsif (i.class.to_s == "electronicdocument") # Autores APA string += i. # fecha de publicacion APA string += " (#{i.date}" if (i.date == datePrev && i. == ) string += (@sufijo+97).chr string += "). " @sufijo += 1 else string += "). " end = i. datePrev = i.date # Título articuloAPA string += " #{i.title.capitalize}" # Edición articuloAPA string += " (#{i.edition})." # Nombre periodico APA string += " [#{i.journal}] " # URL de paginas APA string += " #{i.url}.\n\n " end end return string end |