Class: DLinkedList::Referencia

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/dLinkedList/dLinkedList.rb

Overview

Referencia bibliográfica básica.

Direct Known Subclasses

Articulo, EDocumento, Libro

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Referencia

Inicializa la referencia usando el DSL especificado en el bloque block.

Raises:

  • (ArgumentError)


23
24
25
26
# File 'lib/dLinkedList/dLinkedList.rb', line 23

def initialize(&block)
  instance_eval &block
  raise ArgumentError, "Debe haber al menos un autor" unless @autores.length > 0
end

Instance Attribute Details

#autoresObject (readonly)

Array de autores.



16
17
18
# File 'lib/dLinkedList/dLinkedList.rb', line 16

def autores
  @autores
end

#fecha_publicacionObject (readonly)

Fecha de publicación.



20
21
22
# File 'lib/dLinkedList/dLinkedList.rb', line 20

def fecha_publicacion
  @fecha_publicacion
end

#tituloObject (readonly)

Título de la obra.



18
19
20
# File 'lib/dLinkedList/dLinkedList.rb', line 18

def titulo
  @titulo
end

Instance Method Details

#<=>(c_ref) ⇒ Object

Comparación de referencias según los criterios del formato APA.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dLinkedList/dLinkedList.rb', line 55

def <=>(c_ref)      
  ref_ord = @autores[0][:apellidos] <=> c_ref.autores[0][:apellidos]
  if ref_ord == 0 # Primer autor con el mismo apellido       
    ref_ord = @autores[0][:nombre] <=> c_ref.autores[0][:nombre]
    if ref_ord == 0 # Mismo primer autor
      ref_ord = autores_to_s <=> c_ref.autores_to_s
      if ref_ord == 0 # Mismos autores
        ref_ord = @fecha_publicacion.year <=> c_ref.fecha_publicacion.year
        if ref_ord == 0 # Mismos autores y año de publicación
          ref_ord = @titulo <=> c_ref.titulo
        end
      end
    end       
  end
  
  return ref_ord
end

#to_sObject

Devuelve una cadena con el contenido de la referencia en formato APA.

Formato: Apellidos_Autor, Nombre_Autor [& Apellidos_Autor, Nombre_Autor…] (Fecha de publicación). Título.



47
48
49
50
51
52
# File 'lib/dLinkedList/dLinkedList.rb', line 47

def to_s      
  s = ''
  s << autores_to_s
  s << "(#{@fecha_publicacion.strftime('%-d/%-m/%Y')}). #{@titulo}."
  return s
end