biblio_alu0100845235 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +6 -0
  5. data/= +0 -0
  6. data/CODE_OF_CONDUCT.md +13 -0
  7. data/Gemfile +6 -0
  8. data/Guardfile +82 -0
  9. data/LICENSE.txt +21 -0
  10. data/README.md +7 -0
  11. data/Rakefile +7 -0
  12. data/biblio.gemspec +34 -0
  13. data/biblio.rb +12 -0
  14. data/biblio_spec.1.rb +478 -0
  15. data/biblio_spec.rb +535 -0
  16. data/bin/console +14 -0
  17. data/bin/setup +7 -0
  18. data/doc/=.html +97 -0
  19. data/doc/Biblio.html +109 -0
  20. data/doc/CODE_OF_CONDUCT_md.html +127 -0
  21. data/doc/Cita.html +278 -0
  22. data/doc/Edocumento.html +275 -0
  23. data/doc/Gemfile.html +104 -0
  24. data/doc/Gemfile_lock.html +204 -0
  25. data/doc/Guardfile.html +182 -0
  26. data/doc/LICENSE_txt.html +119 -0
  27. data/doc/Libro.html +391 -0
  28. data/doc/List.html +591 -0
  29. data/doc/Object.html +116 -0
  30. data/doc/Periodico.html +218 -0
  31. data/doc/Publicacion.html +321 -0
  32. data/doc/README_md.html +115 -0
  33. data/doc/Rakefile.html +103 -0
  34. data/doc/Referencia.html +467 -0
  35. data/doc/Revista.html +275 -0
  36. data/doc/biblio_gemspec.html +132 -0
  37. data/doc/bin/setup.html +103 -0
  38. data/doc/created.rid +30 -0
  39. data/doc/css/fonts.css +167 -0
  40. data/doc/css/rdoc.css +590 -0
  41. data/doc/fonts/Lato-Light.ttf +0 -0
  42. data/doc/fonts/Lato-LightItalic.ttf +0 -0
  43. data/doc/fonts/Lato-Regular.ttf +0 -0
  44. data/doc/fonts/Lato-RegularItalic.ttf +0 -0
  45. data/doc/fonts/SourceCodePro-Bold.ttf +0 -0
  46. data/doc/fonts/SourceCodePro-Regular.ttf +0 -0
  47. data/doc/images/add.png +0 -0
  48. data/doc/images/arrow_up.png +0 -0
  49. data/doc/images/brick.png +0 -0
  50. data/doc/images/brick_link.png +0 -0
  51. data/doc/images/bug.png +0 -0
  52. data/doc/images/bullet_black.png +0 -0
  53. data/doc/images/bullet_toggle_minus.png +0 -0
  54. data/doc/images/bullet_toggle_plus.png +0 -0
  55. data/doc/images/date.png +0 -0
  56. data/doc/images/delete.png +0 -0
  57. data/doc/images/find.png +0 -0
  58. data/doc/images/loadingAnimation.gif +0 -0
  59. data/doc/images/macFFBgHack.png +0 -0
  60. data/doc/images/package.png +0 -0
  61. data/doc/images/page_green.png +0 -0
  62. data/doc/images/page_white_text.png +0 -0
  63. data/doc/images/page_white_width.png +0 -0
  64. data/doc/images/plugin.png +0 -0
  65. data/doc/images/ruby.png +0 -0
  66. data/doc/images/tag_blue.png +0 -0
  67. data/doc/images/tag_green.png +0 -0
  68. data/doc/images/transparent.png +0 -0
  69. data/doc/images/wrench.png +0 -0
  70. data/doc/images/wrench_orange.png +0 -0
  71. data/doc/images/zoom.png +0 -0
  72. data/doc/index.html +125 -0
  73. data/doc/js/darkfish.js +161 -0
  74. data/doc/js/jquery.js +4 -0
  75. data/doc/js/navigation.js +142 -0
  76. data/doc/js/navigation.js.gz +0 -0
  77. data/doc/js/search.js +109 -0
  78. data/doc/js/search_index.js +1 -0
  79. data/doc/js/search_index.js.gz +0 -0
  80. data/doc/js/searcher.js +228 -0
  81. data/doc/js/searcher.js.gz +0 -0
  82. data/doc/table_of_contents.html +294 -0
  83. data/lib/biblio/cita.rb +30 -0
  84. data/lib/biblio/edocumento.rb +34 -0
  85. data/lib/biblio/libro.rb +62 -0
  86. data/lib/biblio/list.rb +133 -0
  87. data/lib/biblio/node.rb +2 -0
  88. data/lib/biblio/periodico.rb +28 -0
  89. data/lib/biblio/publicacion.rb +23 -0
  90. data/lib/biblio/referencia.rb +84 -0
  91. data/lib/biblio/revista.rb +34 -0
  92. data/lib/biblio/version.rb +3 -0
  93. data/lib/biblio.rb +17 -0
  94. data/spec_helper.1.rb +2 -0
  95. data/spec_helper.rb +4 -0
  96. metadata +228 -0
@@ -0,0 +1,294 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>Table of Contents - RDoc Documentation</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "./";
11
+ </script>
12
+
13
+ <script src="./js/jquery.js"></script>
14
+ <script src="./js/darkfish.js"></script>
15
+
16
+ <link href="./css/fonts.css" rel="stylesheet">
17
+ <link href="./css/rdoc.css" rel="stylesheet">
18
+
19
+
20
+
21
+ <body id="top" class="table-of-contents">
22
+ <main role="main">
23
+ <h1 class="class">Table of Contents - RDoc Documentation</h1>
24
+
25
+ <h2 id="pages">Pages</h2>
26
+ <ul>
27
+ <li class="file">
28
+ <a href="=.html">=</a>
29
+ </li>
30
+ <li class="file">
31
+ <a href="CODE_OF_CONDUCT_md.html">CODE_OF_CONDUCT</a>
32
+
33
+ <ul>
34
+ <li><a href="CODE_OF_CONDUCT_md.html#label-Contributor+Code+of+Conduct">Contributor Code of Conduct</a>
35
+ </ul>
36
+ </li>
37
+ <li class="file">
38
+ <a href="Gemfile.html">Gemfile</a>
39
+ </li>
40
+ <li class="file">
41
+ <a href="Gemfile_lock.html">Gemfile.lock</a>
42
+ </li>
43
+ <li class="file">
44
+ <a href="Guardfile.html">Guardfile</a>
45
+ </li>
46
+ <li class="file">
47
+ <a href="LICENSE_txt.html">LICENSE</a>
48
+ </li>
49
+ <li class="file">
50
+ <a href="README_md.html">README</a>
51
+
52
+ <ul>
53
+ <li><a href="README_md.html#label-Pr-C3-A1ctica+11+de+LPP">Práctica 11 de LPP</a>
54
+ <li><a href="README_md.html#label-Desarrollador">Desarrollador</a>
55
+ </ul>
56
+ </li>
57
+ <li class="file">
58
+ <a href="Rakefile.html">Rakefile</a>
59
+ </li>
60
+ <li class="file">
61
+ <a href="biblio_gemspec.html">biblio.gemspec</a>
62
+ </li>
63
+ <li class="file">
64
+ <a href="bin/setup.html">setup</a>
65
+ </li>
66
+
67
+ </ul>
68
+
69
+ <h2 id="classes">Classes and Modules</h2>
70
+ <ul>
71
+ <li class="module">
72
+ <a href="Biblio.html">Biblio</a>
73
+ </li>
74
+ <li class="class">
75
+ <a href="Cita.html">Cita</a>
76
+ </li>
77
+ <li class="class">
78
+ <a href="Edocumento.html">Edocumento</a>
79
+ </li>
80
+ <li class="class">
81
+ <a href="Libro.html">Libro</a>
82
+ </li>
83
+ <li class="class">
84
+ <a href="List.html">List</a>
85
+ </li>
86
+ <li class="class">
87
+ <a href="Object.html">Object</a>
88
+ </li>
89
+ <li class="class">
90
+ <a href="Periodico.html">Periodico</a>
91
+ </li>
92
+ <li class="class">
93
+ <a href="Publicacion.html">Publicacion</a>
94
+ </li>
95
+ <li class="class">
96
+ <a href="Referencia.html">Referencia</a>
97
+ </li>
98
+ <li class="class">
99
+ <a href="Revista.html">Revista</a>
100
+ </li>
101
+ </ul>
102
+
103
+ <h2 id="methods">Methods</h2>
104
+ <ul>
105
+
106
+ <li class="method">
107
+ <a href="Cita.html#method-c-new">::new</a>
108
+ &mdash;
109
+ <span class="container">Cita</span>
110
+
111
+ <li class="method">
112
+ <a href="Edocumento.html#method-c-new">::new</a>
113
+ &mdash;
114
+ <span class="container">Edocumento</span>
115
+
116
+ <li class="method">
117
+ <a href="Libro.html#method-c-new">::new</a>
118
+ &mdash;
119
+ <span class="container">Libro</span>
120
+
121
+ <li class="method">
122
+ <a href="List.html#method-c-new">::new</a>
123
+ &mdash;
124
+ <span class="container">List</span>
125
+
126
+ <li class="method">
127
+ <a href="Periodico.html#method-c-new">::new</a>
128
+ &mdash;
129
+ <span class="container">Periodico</span>
130
+
131
+ <li class="method">
132
+ <a href="Publicacion.html#method-c-new">::new</a>
133
+ &mdash;
134
+ <span class="container">Publicacion</span>
135
+
136
+ <li class="method">
137
+ <a href="Referencia.html#method-c-new">::new</a>
138
+ &mdash;
139
+ <span class="container">Referencia</span>
140
+
141
+ <li class="method">
142
+ <a href="Revista.html#method-c-new">::new</a>
143
+ &mdash;
144
+ <span class="container">Revista</span>
145
+
146
+ <li class="method">
147
+ <a href="Referencia.html#method-i-3C-3D-3E">#&lt;=&gt;</a>
148
+ &mdash;
149
+ <span class="container">Referencia</span>
150
+
151
+ <li class="method">
152
+ <a href="Referencia.html#method-i-autor">#autor</a>
153
+ &mdash;
154
+ <span class="container">Referencia</span>
155
+
156
+ <li class="method">
157
+ <a href="Cita.html#method-i-citar">#citar</a>
158
+ &mdash;
159
+ <span class="container">Cita</span>
160
+
161
+ <li class="method">
162
+ <a href="Cita.html#method-i-clear">#clear</a>
163
+ &mdash;
164
+ <span class="container">Cita</span>
165
+
166
+ <li class="method">
167
+ <a href="List.html#method-i-clear">#clear</a>
168
+ &mdash;
169
+ <span class="container">List</span>
170
+
171
+ <li class="method">
172
+ <a href="List.html#method-i-each">#each</a>
173
+ &mdash;
174
+ <span class="container">List</span>
175
+
176
+ <li class="method">
177
+ <a href="Referencia.html#method-i-editorial">#editorial</a>
178
+ &mdash;
179
+ <span class="container">Referencia</span>
180
+
181
+ <li class="method">
182
+ <a href="Referencia.html#method-i-fecha">#fecha</a>
183
+ &mdash;
184
+ <span class="container">Referencia</span>
185
+
186
+ <li class="method">
187
+ <a href="List.html#method-i-get_pos">#get_pos</a>
188
+ &mdash;
189
+ <span class="container">List</span>
190
+
191
+ <li class="method">
192
+ <a href="List.html#method-i-insert">#insert</a>
193
+ &mdash;
194
+ <span class="container">List</span>
195
+
196
+ <li class="method">
197
+ <a href="Libro.html#method-i-isbn">#isbn</a>
198
+ &mdash;
199
+ <span class="container">Libro</span>
200
+
201
+ <li class="method">
202
+ <a href="Publicacion.html#method-i-issn">#issn</a>
203
+ &mdash;
204
+ <span class="container">Publicacion</span>
205
+
206
+ <li class="method">
207
+ <a href="Libro.html#method-i-n_edicion">#n_edicion</a>
208
+ &mdash;
209
+ <span class="container">Libro</span>
210
+
211
+ <li class="method">
212
+ <a href="Revista.html#method-i-numero">#numero</a>
213
+ &mdash;
214
+ <span class="container">Revista</span>
215
+
216
+ <li class="method">
217
+ <a href="Publicacion.html#method-i-pagina_fin">#pagina_fin</a>
218
+ &mdash;
219
+ <span class="container">Publicacion</span>
220
+
221
+ <li class="method">
222
+ <a href="Publicacion.html#method-i-pagina_inicio">#pagina_inicio</a>
223
+ &mdash;
224
+ <span class="container">Publicacion</span>
225
+
226
+ <li class="method">
227
+ <a href="List.html#method-i-pop_back">#pop_back</a>
228
+ &mdash;
229
+ <span class="container">List</span>
230
+
231
+ <li class="method">
232
+ <a href="List.html#method-i-pop_front">#pop_front</a>
233
+ &mdash;
234
+ <span class="container">List</span>
235
+
236
+ <li class="method">
237
+ <a href="List.html#method-i-push_back">#push_back</a>
238
+ &mdash;
239
+ <span class="container">List</span>
240
+
241
+ <li class="method">
242
+ <a href="List.html#method-i-push_front">#push_front</a>
243
+ &mdash;
244
+ <span class="container">List</span>
245
+
246
+ <li class="method">
247
+ <a href="Libro.html#method-i-serie">#serie</a>
248
+ &mdash;
249
+ <span class="container">Libro</span>
250
+
251
+ <li class="method">
252
+ <a href="Referencia.html#method-i-titulo">#titulo</a>
253
+ &mdash;
254
+ <span class="container">Referencia</span>
255
+
256
+ <li class="method">
257
+ <a href="Cita.html#method-i-to_s">#to_s</a>
258
+ &mdash;
259
+ <span class="container">Cita</span>
260
+
261
+ <li class="method">
262
+ <a href="Edocumento.html#method-i-to_s">#to_s</a>
263
+ &mdash;
264
+ <span class="container">Edocumento</span>
265
+
266
+ <li class="method">
267
+ <a href="Libro.html#method-i-to_s">#to_s</a>
268
+ &mdash;
269
+ <span class="container">Libro</span>
270
+
271
+ <li class="method">
272
+ <a href="Periodico.html#method-i-to_s">#to_s</a>
273
+ &mdash;
274
+ <span class="container">Periodico</span>
275
+
276
+ <li class="method">
277
+ <a href="Revista.html#method-i-to_s">#to_s</a>
278
+ &mdash;
279
+ <span class="container">Revista</span>
280
+
281
+ <li class="method">
282
+ <a href="Edocumento.html#method-i-url">#url</a>
283
+ &mdash;
284
+ <span class="container">Edocumento</span>
285
+ </ul>
286
+ </main>
287
+
288
+
289
+ <footer id="validator-badges" role="contentinfo">
290
+ <p><a href="http://validator.w3.org/check/referer">Validate</a>
291
+ <p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.2.0.
292
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
293
+ </footer>
294
+
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ class Cita
3
+ def initialize
4
+ @lista = List.new
5
+ yield self if block_given?
6
+ end
7
+
8
+ def citar(referencia)
9
+ raise ArgumentError, "La referencia debe ser del tipo Referencia" unless referencia.is_a?(Referencia)
10
+ @lista.push_back(referencia)
11
+
12
+ aux = @lista.sort
13
+ @lista.clear
14
+ aux.each do |n|
15
+ @lista.push_back(n)
16
+ end
17
+ end
18
+
19
+ def clear
20
+ @lista.clear
21
+ end
22
+
23
+ def to_s
24
+ salida = ""
25
+ @lista.each do |n|
26
+ salida = salida + n.to_s + "\n"
27
+ end
28
+ salida
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+ class Edocumento < Publicacion
3
+ attr_accessor :dir_url
4
+
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ def url(text)
10
+ raise ArgumentError, "La url debe ser de tipo String" unless text.is_a?(String)
11
+ @dir_url = text
12
+ end
13
+
14
+ def to_s
15
+ # formateamos autores
16
+ str_autores = ""
17
+ @autores.each do |autor|
18
+ str_autores += autor + ", "
19
+ end
20
+ str_autores = str_autores[0, str_autores.length - 2]
21
+ if @autores.length > 1
22
+ str_autores = str_autores.sub(", " + @autores.last, " & " + @autores.last)
23
+ end
24
+
25
+ # generamos string de salida
26
+ salida=""
27
+ if(@pfin != nil)
28
+ salida = "#{str_autores} (#{@date_p.strftime("%d, %B %Y")}). #{@title}.\n\t#{@editor}, p. #{@pinicio} - #{@pfin}.\n\tISSN: #{@issn}\n\tDisponible en: #{@dir_url}"
29
+ else
30
+ salida = "#{str_autores} (#{@date_p.strftime("%d, %B %Y")}).\n\t#{@title}.\n\t#{@editor}, p. #{@pinicio}.\n\tISSN: #{@issn}\n\tDisponible en: #{@dir_url}"
31
+ end
32
+ salida
33
+ end
34
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ class Libro < Referencia
3
+ attr_accessor :series, :n_edition, :isbns
4
+
5
+ def initialize
6
+ @isbns = []
7
+ super
8
+ end
9
+
10
+ def serie(text)
11
+ if !text.nil?
12
+ raise ArgumentError, "La serie debe ser un String" unless text.is_a?(String)
13
+ end
14
+ @series = text
15
+ end
16
+
17
+ def n_edicion(number)
18
+ raise ArgumentError, "Numero de edicion debe ser un Numeric" unless number.is_a?(Numeric)
19
+ @n_edition = number
20
+ end
21
+
22
+ def isbn(text)
23
+ raise ArgumentError, "El ISBN debe ser un String" unless text.is_a?(String)
24
+ @isbns << text
25
+ end
26
+
27
+ def to_s
28
+ # formateamos autores
29
+ str_autores = ""
30
+ @autores.each do |autor|
31
+ str_autores += autor + ", "
32
+ end
33
+ str_autores = str_autores[0, str_autores.length - 2]
34
+ if @autores.length > 1
35
+ str_autores = str_autores.sub(", " + @autores.last, " & " + @autores.last)
36
+ end
37
+
38
+ # formateamos isbn
39
+ str_isbn = ""
40
+ @isbns.each do |n_isbn|
41
+ if n_isbn.length > 10
42
+ str_isbn += "ISBN-13: #{n_isbn}\n"
43
+ else
44
+ str_isbn += "ISBN-10: #{n_isbn}\n"
45
+ end
46
+ end
47
+
48
+ if @sufijo != nil
49
+ str_sufijo = " " + @sufijo
50
+ else
51
+ str_sufijo = ""
52
+ end
53
+
54
+ salida=""
55
+ if series != nil
56
+ salida = "#{str_autores} (#{@date_p.strftime("%d, %B %Y")}#{str_sufijo}). #{@title} (#{@series}).\n\t#{@editor}; #{@n_edition} edición\n\t#{str_isbn}"
57
+ else
58
+ salida = "#{str_autores} (#{@date_p.strftime("%d, %B %Y")}#{str_sufijo}). #{@title}.\n\t#{@editor}; #{@n_edition} edición\n\t#{str_isbn}"
59
+ end
60
+ salida
61
+ end
62
+ end
@@ -0,0 +1,133 @@
1
+ # encoding: utf-8
2
+ #require "./node.rb"
3
+ # create a Struct with :value and :next
4
+
5
+
6
+ class List
7
+ include Enumerable
8
+ attr_reader :front, :end, :size
9
+
10
+ def initialize(value = nil)
11
+ @size = 0
12
+ @front = Node.new(nil, nil, nil)
13
+ @end = @front
14
+
15
+ if value != nil
16
+ push_front(value)
17
+ end
18
+ end
19
+
20
+ def push_back(value)
21
+ if size == 0
22
+ @end = Node.new(value, nil, nil)
23
+ @front = @end
24
+ else
25
+ @end.next = Node.new(value, @end, nil)
26
+ @end = @end.next
27
+ end
28
+ @size = @size + 1
29
+ nil
30
+ end
31
+
32
+ def push_front(value)
33
+ if size == 0
34
+ @front = Node.new(value, nil, nil)
35
+ @end = @front
36
+ else
37
+ @front.previous = Node.new(value, nil, @front)
38
+ @front= @front.previous
39
+ end
40
+ @size = @size + 1
41
+ nil
42
+ end
43
+
44
+ def pop_back
45
+ aux = nil
46
+ if size == 1
47
+ aux = @end.value
48
+ @end = Node.new(nil, nil, nil)
49
+ @front = @end
50
+ @size = @size - 1
51
+ elsif size > 1
52
+ aux = @end.value
53
+ @end = @end.previous
54
+ @size = @size - 1
55
+ end
56
+ aux
57
+ end
58
+
59
+ def pop_front
60
+ aux = nil
61
+ if size == 1
62
+ aux = @front.value
63
+ @front = Node.new(nil, nil, nil)
64
+ @end = @front
65
+ @size = @size - 1
66
+ elsif size > 1
67
+ aux = @front.value
68
+ @front = @front.next
69
+ @size = @size - 1
70
+ end
71
+ aux
72
+ end
73
+
74
+ def insert(position, value)
75
+ if position >= 0 && position <= @size
76
+
77
+ if position == 0 && @size == 0 # La lista esta vacia
78
+ push_front(value)
79
+ elsif position == @size
80
+ push_back(value)
81
+ elsif position == 0
82
+ push_front(value)
83
+ else
84
+ # Buscamos el nodo anterior a la posicion
85
+ i = 0
86
+ aux = @front
87
+ while i < position-1
88
+ aux = aux.next
89
+ i = i+1
90
+ end
91
+
92
+ #realizamos swap
93
+ swap = aux.next
94
+ aux.next = Node.new(value, aux, swap)
95
+ aux = aux.next
96
+ @size = @size + 1
97
+ end
98
+ end
99
+ nil
100
+ end
101
+
102
+ def get_pos(position)
103
+ if position < @size
104
+ aux = @front
105
+ if position > 0
106
+ i = 0
107
+ while i < position
108
+ aux = aux.next
109
+ i = i+1
110
+ end
111
+ end
112
+ else
113
+ aux = nil
114
+ end
115
+ aux
116
+ end
117
+
118
+ def each
119
+ return nil unless @size > 0
120
+ aux = @front
121
+ until aux.nil?
122
+ yield aux.value
123
+ aux = aux.next
124
+ end
125
+ end
126
+
127
+ def clear
128
+ @size = 0
129
+ @front = Node.new(nil, nil, nil)
130
+ @end = @front
131
+ end
132
+
133
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ Node = Struct.new(:value, :previous, :next)
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ class Periodico < Publicacion
3
+
4
+ def initialize
5
+ super
6
+ end
7
+
8
+ def to_s
9
+ # formateamos autores
10
+ str_autores = ""
11
+ @autores.each do |autor|
12
+ str_autores += autor + ", "
13
+ end
14
+ str_autores = str_autores[0, str_autores.length - 2]
15
+ if @autores.length > 1
16
+ str_autores = str_autores.sub(", " + @autores.last, " & " + @autores.last)
17
+ end
18
+
19
+ # generamos string de salida
20
+ salida=""
21
+ if(@pfin != nil)
22
+ salida = "#{str_autores} (#{@date_p.strftime("%d, %B %Y")}). #{@title}.\n\t#{@editor}, p. #{@pinicio} - #{@pfin}.\n\tISSN: #{@issn}"
23
+ else
24
+ salida = "#{str_autores} (#{@date_p.strftime("%d, %B %Y")}). #{@title}.\n\t#{@editor}, p. #{@pinicio}.\n\tISSN: #{@issn}"
25
+ end
26
+ salida
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ class Publicacion < Referencia
3
+ attr_accessor :pinicio, :pfin, :issns
4
+
5
+ def initialize
6
+ super
7
+ end
8
+
9
+ def pagina_inicio(number)
10
+ raise ArgumentError, "Numero de pagina debe se un Numeric" unless number.is_a?(Numeric)
11
+ @pinicio = number
12
+ end
13
+
14
+ def pagina_fin(number)
15
+ raise ArgumentError, "Numero de pagina debe se un Numeric" unless number.is_a?(Numeric)
16
+ @pfin = number
17
+ end
18
+
19
+ def issn(text)
20
+ raise ArgumentError, "El codigo ISSN debe se un String" unless text.is_a?(String)
21
+ @issns = text
22
+ end
23
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require 'date'
3
+
4
+ class Referencia
5
+ include Comparable
6
+ attr_accessor :autores, :title, :editor, :date_p, :sufijo
7
+
8
+ def initialize(&block)
9
+ @autores = []
10
+ if block_given?
11
+ if block.arity == 1
12
+ yield self
13
+ else
14
+ instance_eval &block
15
+ end
16
+ end
17
+ end
18
+
19
+ def autor(name)
20
+ raise ArgumentError, "Los autores deben ser un String" unless name.is_a?(String)
21
+ # Formateamos el nombre
22
+ aux = name.split
23
+ raise ArgumentError, "El nombre del autor debe contener nombre y apellido" unless aux.length > 1
24
+
25
+ nombre = aux.pop + ", "
26
+ aux.each do |n|
27
+ if n.length > 0
28
+ nombre << n[0] + ". "
29
+ end
30
+ end
31
+
32
+ # Insertamos y ordenamos el array
33
+ @autores << nombre[0..-2]
34
+ @autores = @autores.sort
35
+ end
36
+
37
+ def titulo(text)
38
+ raise ArgumentError, "El titulo debe ser un String" unless text.is_a?(String)
39
+ text = text.downcase
40
+ aux = text.split
41
+ aux[0].capitalize!
42
+ aux.each do |p|
43
+ if p.length > 2
44
+ p.capitalize!
45
+ end
46
+ end
47
+ @title = aux.join " "
48
+ end
49
+
50
+ def editorial(text)
51
+ raise ArgumentError, "Editorial debe ser un String" unless text.is_a?(String)
52
+ @editor = text
53
+ end
54
+
55
+ def fecha(text)
56
+ raise ArgumentError, "La fecha de publicacion debe ser un String" unless text.is_a?(String)
57
+ @date_p = Date.parse(text)
58
+ end
59
+
60
+ def <=>(other)
61
+ # devolvemos nil si no son del tipo Referencia
62
+ return nil unless other.is_a? Referencia
63
+ # realizamos las comparaciones necesarias
64
+
65
+ # Comprobamos si tienen el mismo apellido del primer autor, ordenamos por el primer autor
66
+ return @autores.first <=> other.autores.first unless @autores.first == other.autores.first
67
+ # Comprobamos cantidad de autores, priorizamos los que tengan menor numero de autores
68
+ return @autores.length <=> other.autores.length unless @autores.length == other.autores.length
69
+ # Comprobamos son exactamente los mismos autores, si no lo son ordenamos por la lista completa de autores
70
+ return @autores <=> other.autores unless @autores & other.autores == @autores
71
+ # Ordenamos por año de publicacion
72
+ return @date_p.year <=> other.date_p.year unless @date_p.year == other.date_p.year
73
+ # Ordenamos por titulo
74
+ if @title != other.title
75
+ # Insertamos sufijos
76
+ mes = ["ENE", "FEB", "MAR", "ABR", "MAY", "JUN", "JUL", "AGO", "SEP", "OPT", "NOV", "DIC"]
77
+ @sufijo = mes[@date_p.mon - 1]
78
+ other.sufijo = mes[other.date_p.mon - 1]
79
+ return @title <=> other.title
80
+ end
81
+
82
+ return 0
83
+ end
84
+ end