Class: APA

Inherits:
Object
  • Object
show all
Defined in:
lib/prct11/APA.rb

Instance Method Summary collapse

Constructor Details

#initializeAPA

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

#eachObject



55
56
57
# File 'lib/prct11/APA.rb', line 55

def each
  @lista.each{ |i| yield i}
end

#insert(reference) ⇒ Object

Raises:

  • (ArgumentError)


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.authors.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.authors.last
  end
  reference.authors = str
  @lista.insert_by_end(reference)
end

#to_sObject



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
  authorsPrev = ""
  datePrev = ""
  listSort = @lista.sort
  string = ""
  listSort.each do |i|
    if (i.instance_of? Book)
      
      # Autores APA
      string += i.authors
    
      # Año de publicacion APA
      element = i.date.split(/\//)
      string += " (#{element[2]}"
      
      
      if (i.date == datePrev &&  i.authors == authorsPrev)
        string += (@sufijo+97).chr
        string += "). "
        @sufijo += 1
          else
            string += "). "
      end
      authorsPrev = i.authors
      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.authors
    
      # fecha de publicacion APA
      string += " (#{i.date}"
      
      if (i.date == datePrev &&  i.authors == authorsPrev)
        string += (@sufijo+97).chr
        string += "). "
        @sufijo += 1
          else
            string += "). "
      end
      authorsPrev = i.authors
      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.authors
    
      # fecha de publicacion APA
      string += " (#{i.date}"
      
      if (i.date == datePrev &&  i.authors == authorsPrev)
        string += (@sufijo+97).chr
        string += "). "
        @sufijo += 1
          else
            string += "). "
      end
      authorsPrev = i.authors
      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