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

- (Referencia) initialize(&block)

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

- (Object) autores

Returns the value of attribute autores



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

def autores
  @autores
end

- (Object) editorial

Returns the value of attribute editorial



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

def editorial
  @editorial
end

- (Object) fecha

Returns the value of attribute fecha



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

def fecha
  @fecha
end

- (Object) isbn10

Returns the value of attribute isbn10



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

def isbn10
  @isbn10
end

- (Object) isbn13

Returns the value of attribute isbn13



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

def isbn13
  @isbn13
end

- (Object) nedicion

Returns the value of attribute nedicion



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

def nedicion
  @nedicion
end

- (Object) serie

Returns the value of attribute serie



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

def serie
  @serie
end

- (Object) titulo

Returns the value of attribute titulo



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

def titulo
  @titulo
end

Instance Method Details

- (Object) <=>(other)



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

- (Object) comprobar



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

- (Object) to_s



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

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