Class: Biblio

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

Direct Known Subclasses

Articulo, Libro

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(titulo, &block) ⇒ Biblio

Returns a new instance of Biblio.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/biblioalu0100815146/biblio.rb', line 6

def initialize(titulo, &block)

     self.titulo = titulo
     self.autor = []
     self.fecha = []

     if block_given?  
          if block.arity == 1
               yield self
          else
               instance_eval &block 
          end
     end
end

Instance Attribute Details

#autorObject

Returns the value of attribute autor.



4
5
6
# File 'lib/biblioalu0100815146/biblio.rb', line 4

def autor
  @autor
end

#fechaObject

Returns the value of attribute fecha.



4
5
6
# File 'lib/biblioalu0100815146/biblio.rb', line 4

def fecha
  @fecha
end

#tituloObject

Returns the value of attribute titulo.



4
5
6
# File 'lib/biblioalu0100815146/biblio.rb', line 4

def titulo
  @titulo
end

Instance Method Details

#<=>(other) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/biblioalu0100815146/biblio.rb', line 33

def <=>(other)
     
     if(@autor != other.autor)
          @autor <=> other.autor
     elsif(@autor == other.autor)
          @fecha <=> other.fecha
     elsif(@fecha == other.fecha && @autor == other.autor)
          @titulo <=> other.titulo
     end
end

#author(name, options = {}) ⇒ Object



27
28
29
30
31
# File 'lib/biblioalu0100815146/biblio.rb', line 27

def author(name, options = {})
     author = name
     author << " (#{options[:amount]})" if options[:amount]
     autor << author
end

#date(name, options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/biblioalu0100815146/biblio.rb', line 21

def date(name, options = {})
     date = name
     
     fecha << date
end

#to_sObject



45
46
47
# File 'lib/biblioalu0100815146/biblio.rb', line 45

def to_s()
   @salida = " AUTOR/ES: " + "#{@autor}" + " TITULO: " + "#{@titulo}" + " FECHA: " + "#{@fecha}" 
end