Class: Referencia

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

Direct Known Subclasses

Periodico

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Referencia

Returns a new instance of Referencia.



4
5
6
# File 'lib/bibliogem/Referencia.rb', line 4

def initialize &block
	(block.arity<1 ? (instance_eval &block) : block.call(self)) if block_given?
end

Instance Attribute Details

#autoresObject

Returns the value of attribute autores.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def autores
  @autores
end

#editorialObject

Returns the value of attribute editorial.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def editorial
  @editorial
end

#fechaObject

Returns the value of attribute fecha.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def fecha
  @fecha
end

#isbn10Object

Returns the value of attribute isbn10.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def isbn10
  @isbn10
end

#isbn13Object

Returns the value of attribute isbn13.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def isbn13
  @isbn13
end

#nedicionObject

Returns the value of attribute nedicion.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def nedicion
  @nedicion
end

#serieObject

Returns the value of attribute serie.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def serie
  @serie
end

#tituloObject

Returns the value of attribute titulo.



3
4
5
# File 'lib/bibliogem/Referencia.rb', line 3

def titulo
  @titulo
end

Instance Method Details

#<=>(other) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bibliogem/Referencia.rb', line 27

def <=> other
	if(@autores == other.autores)
		if(@fecha == other.fecha)
			if(@titulo == other.titulo)
				return 0
			else
				aux=[@titulo, other.titulo]
				aux.sort_by! do |t|
					t
				end
				if(aux.first == @titulo)
					return -1
				end
				return 1
			end
		elsif(@fecha < other.fecha)
			return -1
		else
			return 1
		end
	else
		aux=[@autores, other.autores]
		aux.sort_by! do |t|
			t
		end
		if(aux.first == @autores)
			return -1
		end
		return 1
	end
end

#comprobarObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bibliogem/Referencia.rb', line 7

def comprobar
	if !aut.any?
		raise ArgumentError.new("Error: Se requiere al menos un autor")
	end
	if tit.nil?
		raise ArgumentError.new("Error: Se requiere un tiulo")
	end
	if edi.nil?
		raise ArgumentError.new("Error: Se requiere una editorial")
	end
	if ne.nil?
		raise ArgumentError.new("Error Se requiere un numero de edicion")
	end
	if fe.nil?
		raise ArgumentError.new("Error: Se requiere una fecha con formato %d-%m-%Y")
	end
	if is10.nil? && is13.nil?
		raise ArgumentError.new("Error: Se requiere al menos un codigo isbn")
	end
end

#to_sObject



58
59
60
# File 'lib/bibliogem/Referencia.rb', line 58

def to_s
	"#{@autores}, #{@titulo}, #{@serie}, #{@editorial}, #{@nedicion}, #{@fecha}, #{@isbn10}, #{@isbn13}"
end