dLinkedList 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +9 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +8 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +82 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +4 -0
  10. data/Rakefile +11 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/dLinkedList.gemspec +29 -0
  14. data/html/DLinkedList.html +111 -0
  15. data/html/DLinkedList/Articulo.html +321 -0
  16. data/html/DLinkedList/EDocumento.html +321 -0
  17. data/html/DLinkedList/Libro.html +370 -0
  18. data/html/DLinkedList/List.html +464 -0
  19. data/html/DLinkedList/Node.html +205 -0
  20. data/html/DLinkedList/Referencia.html +464 -0
  21. data/html/created.rid +4 -0
  22. data/html/css/fonts.css +167 -0
  23. data/html/css/rdoc.css +590 -0
  24. data/html/fonts/Lato-Light.ttf +0 -0
  25. data/html/fonts/Lato-LightItalic.ttf +0 -0
  26. data/html/fonts/Lato-Regular.ttf +0 -0
  27. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  28. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  29. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  30. data/html/images/add.png +0 -0
  31. data/html/images/arrow_up.png +0 -0
  32. data/html/images/brick.png +0 -0
  33. data/html/images/brick_link.png +0 -0
  34. data/html/images/bug.png +0 -0
  35. data/html/images/bullet_black.png +0 -0
  36. data/html/images/bullet_toggle_minus.png +0 -0
  37. data/html/images/bullet_toggle_plus.png +0 -0
  38. data/html/images/date.png +0 -0
  39. data/html/images/delete.png +0 -0
  40. data/html/images/find.png +0 -0
  41. data/html/images/loadingAnimation.gif +0 -0
  42. data/html/images/macFFBgHack.png +0 -0
  43. data/html/images/package.png +0 -0
  44. data/html/images/page_green.png +0 -0
  45. data/html/images/page_white_text.png +0 -0
  46. data/html/images/page_white_width.png +0 -0
  47. data/html/images/plugin.png +0 -0
  48. data/html/images/ruby.png +0 -0
  49. data/html/images/tag_blue.png +0 -0
  50. data/html/images/tag_green.png +0 -0
  51. data/html/images/transparent.png +0 -0
  52. data/html/images/wrench.png +0 -0
  53. data/html/images/wrench_orange.png +0 -0
  54. data/html/images/zoom.png +0 -0
  55. data/html/index.html +92 -0
  56. data/html/js/darkfish.js +161 -0
  57. data/html/js/jquery.js +4 -0
  58. data/html/js/navigation.js +142 -0
  59. data/html/js/navigation.js.gz +0 -0
  60. data/html/js/search.js +109 -0
  61. data/html/js/search_index.js +1 -0
  62. data/html/js/search_index.js.gz +0 -0
  63. data/html/js/searcher.js +228 -0
  64. data/html/js/searcher.js.gz +0 -0
  65. data/html/table_of_contents.html +202 -0
  66. data/lib/dLinkedList.rb +6 -0
  67. data/lib/dLinkedList/dLinkedList.rb +313 -0
  68. data/lib/dLinkedList/version.rb +4 -0
  69. metadata +210 -0
@@ -0,0 +1,6 @@
1
+ require "dLinkedList/version"
2
+ require "dLinkedList/dLinkedList"
3
+
4
+ module DLinkedList
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,313 @@
1
+ # encoding: utf-8
2
+
3
+ # Lista de referencias bibliográficas.
4
+ module DLinkedList
5
+
6
+ # Referencia bibliográfica básica.
7
+ class Referencia
8
+
9
+ # Para manipulación de fechas
10
+ require "date"
11
+
12
+ # Incluye Comparable
13
+ include Comparable
14
+
15
+ # Array de autores.
16
+ attr_reader :autores
17
+ # Título de la obra.
18
+ attr_reader :titulo
19
+ # Fecha de publicación.
20
+ attr_reader :fecha_publicacion
21
+
22
+ # Inicializa la referencia usando el DSL especificado en el bloque _block_.
23
+ def initialize(&block)
24
+ instance_eval &block
25
+ raise ArgumentError, "Debe haber al menos un autor" unless @autores.length > 0
26
+ end
27
+
28
+ # Añade un autor a la lista de autores.
29
+ def autor(autorhash)
30
+ @autores = [] if @autores.nil?
31
+ @autores.push(autorhash)
32
+ end
33
+
34
+ # Establece el título.
35
+ def tit(titulo)
36
+ @titulo = titulo
37
+ end
38
+
39
+ # Establece la fecha de publicación.
40
+ def fecha(fecha_publicacion)
41
+ @fecha_publicacion = Date.strptime(fecha_publicacion, '%d/%m/%Y')
42
+ end
43
+
44
+ # Devuelve una cadena con el contenido de la referencia en formato APA.
45
+ #
46
+ # Formato: Apellidos_Autor, Nombre_Autor [& Apellidos_Autor, Nombre_Autor...] (Fecha de publicación). Título.
47
+ def to_s
48
+ s = ''
49
+ s << autores_to_s
50
+ s << "(#{@fecha_publicacion.strftime('%-d/%-m/%Y')}). #{@titulo}."
51
+ return s
52
+ end
53
+
54
+ # Comparación de referencias según los criterios del formato APA.
55
+ def <=>(c_ref)
56
+ ref_ord = @autores[0][:apellidos] <=> c_ref.autores[0][:apellidos]
57
+ if ref_ord == 0 # Primer autor con el mismo apellido
58
+ ref_ord = @autores[0][:nombre] <=> c_ref.autores[0][:nombre]
59
+ if ref_ord == 0 # Mismo primer autor
60
+ ref_ord = autores_to_s <=> c_ref.autores_to_s
61
+ if ref_ord == 0 # Mismos autores
62
+ ref_ord = @fecha_publicacion.year <=> c_ref.fecha_publicacion.year
63
+ if ref_ord == 0 # Mismos autores y año de publicación
64
+ ref_ord = @titulo <=> c_ref.titulo
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ return ref_ord
71
+ end
72
+
73
+ # Devuelve la lista de autores como cadena.
74
+ def autores_to_s
75
+ s = ''
76
+ @autores.each() { |a| s << a[:apellidos].capitalize << ', ' << a[:nombre][0].capitalize << ". & "}
77
+ return s.chomp("& ")
78
+ end
79
+
80
+ protected :autor, :tit, :fecha, :autores_to_s
81
+
82
+ end
83
+
84
+ # Referencia de un libro.
85
+ class Libro < Referencia
86
+
87
+ # Nº de edición.
88
+ attr_reader :edicion
89
+ # Lugar de publicación.
90
+ attr_reader :lugar_publicacion
91
+ # Editorial.
92
+ attr_reader :editorial
93
+
94
+ # Inicializa la referencia al libro usando el DSL especificado en el bloque _block_.
95
+ def initialize(&block)
96
+ instance_eval &block
97
+ raise ArgumentError, "Debe haber al menos un autor" unless @autores.length > 0
98
+ end
99
+
100
+ # Establece el nº de edición.
101
+ def ed(edicion)
102
+ @edicion = edicion
103
+ end
104
+
105
+ # Establece el lugar de publicación.
106
+ def lugar(lugar_publicacion)
107
+ @lugar_publicacion = lugar_publicacion
108
+ end
109
+
110
+ # Establece la editorial.
111
+ def editor(editorial)
112
+ @editorial = editorial
113
+ end
114
+
115
+ # Devuelve una cadena con el contenido de la referencia al libro en formato APA.
116
+ #
117
+ # Formato: Apellidos_Autor, Nombre_Autor [& Apellidos_Autor, Nombre_Autor...] (Fecha de publicación). Título. (edicion) Lugar de publicación: Editorial.
118
+ def to_s
119
+ return super << " (#{@edicion}ª edición) #{@lugar_publicacion}: #{@editorial}."
120
+ end
121
+
122
+ protected :ed, :lugar, :editor
123
+
124
+ end
125
+
126
+ # Referencia de un artículo.
127
+ class Articulo < Referencia
128
+
129
+ # Título de la publicación.
130
+ attr_reader :titulo_publicacion
131
+ # Nº de las páginas donde está ubicado el artículo.
132
+ attr_reader :paginas
133
+
134
+ # Inicializa la referencia al artículo usando el DSL especificado en el bloque _block_.
135
+ def initialize(&block)
136
+ instance_eval &block
137
+ raise ArgumentError, "Debe haber al menos un autor" unless @autores.length > 0
138
+ end
139
+
140
+ # Establece el título de la publicación.
141
+ def tit_publi(titulo_publicacion)
142
+ @titulo_publicacion = titulo_publicacion
143
+ end
144
+
145
+ # Establece los nº de las páginas donde está ubicado el artículo.
146
+ def pags(paginas)
147
+ @paginas = paginas
148
+ end
149
+
150
+ # Devuelve una cadena con el contenido de la referencia al artículo en formato APA.
151
+ #
152
+ # Formato: Apellidos_Autor, Nombre_Autor [& Apellidos_Autor, Nombre_Autor...] (Fecha de publicación). Título. Título publicación, páginas.
153
+ def to_s
154
+ return super << " #{@titulo_publicacion}, p. #{@paginas}."
155
+ end
156
+
157
+ protected :tit_publi, :pags
158
+
159
+ end
160
+
161
+ # Referencia de un documento electrónico.
162
+ class EDocumento < Referencia
163
+
164
+ # Fecha de recuperación del documento.
165
+ attr_reader :fecha_recuperacion
166
+ # URL de descarga del documento.
167
+ attr_reader :dURL
168
+
169
+ # Inicializa la referencia al documento electrónico usando el DSL especificado en el bloque _block_.
170
+ def initialize(&block)
171
+ instance_eval &block
172
+ raise ArgumentError, "Debe haber al menos un autor" unless @autores.length > 0
173
+ end
174
+
175
+ # Establece la fecha de recuperación del documento.
176
+ def fecha_recup(fecha_recuperacion)
177
+ @fecha_recuperacion = Date.strptime(fecha_recuperacion, '%d/%m/%Y')
178
+ end
179
+
180
+ # Establece la URL de descarga del documento.
181
+ def URL_descarga(dURL)
182
+ @dURL = dURL
183
+ end
184
+
185
+ # Devuelve una cadena con el contenido de la referencia al documento electrónico en formato APA.
186
+ #
187
+ # Formato: Apellidos_Autor, Nombre_Autor [& Apellidos_Autor, Nombre_Autor...] (Fecha de publicación). Título. Fecha de recuperación, URL.
188
+ def to_s
189
+ return super << " Recuperado el #{@fecha_recuperacion.strftime('%-d/%-m/%Y')}, de #{@dURL}."
190
+ end
191
+
192
+ protected :fecha_recup, :URL_descarga
193
+
194
+ end
195
+
196
+ # Nodo que contiene una referencia bibliográfica de cualquier tipo.
197
+ class Node
198
+
199
+ # Valor del nodo (referencia bibliográfica).
200
+ attr_accessor :value
201
+ # Enlace al siguiente nodo de la lista de referencias bibliográficas.
202
+ attr_accessor :next_node
203
+ # Enlace al anterior nodo de la lista de referencias bibliográficas.
204
+ attr_accessor :prev_node
205
+
206
+ # Inicializa el nodo con el valor _value_. Si se especifican también inicializa los enlaces al siguiente y anterior nodo de la lista.
207
+ def initialize(value, next_node = nil, prev_node = nil)
208
+ @value = value
209
+ @next_node = next_node
210
+ @prev_node = prev_node
211
+ end
212
+
213
+ end
214
+
215
+ # Lista de referencias bibliográficas.
216
+ class List
217
+
218
+ # Incluye Enumerable
219
+ include Enumerable
220
+
221
+ # Nodo cabeza de la lista.
222
+ attr_reader :head
223
+ # Nodo cola de la lista.
224
+ attr_reader :tail
225
+ # Tamaño de la lista.
226
+ attr_reader :size
227
+
228
+ # Inicializa la lista vacía.
229
+ def initialize()
230
+ @head = nil
231
+ @tail = nil
232
+ @size = 0
233
+ end
234
+
235
+ # Devuelve si la lista está vacía.
236
+ def empty?()
237
+ return (@head == nil)
238
+ end
239
+
240
+ # Inserta una referencia en la lista vacía.
241
+ def push_empty(ref)
242
+
243
+ raise RuntimeError, "[List.push_empty]: Lista no vacía" unless empty?()
244
+
245
+ nodo = Node.new(ref)
246
+ @head = nodo
247
+ @tail = nodo
248
+ @size += 1
249
+
250
+ return self
251
+
252
+ end
253
+
254
+ # Inserta la referencia _ref_ al final de la lista.
255
+ def push(ref)
256
+ if empty?()
257
+ return push_empty(ref)
258
+ else
259
+ nodo = Node.new(ref, nil, @tail)
260
+ @tail.next_node = nodo
261
+ @tail = nodo
262
+ @size += 1
263
+ return self
264
+ end
265
+ end
266
+
267
+ # Inserta múltiples elementos al final de la lista.
268
+ def push_multi(*refs)
269
+ refs.each { |ref| push(ref)}
270
+ end
271
+
272
+ # Extrae y devuelve la referencia del principio de la lista.
273
+ def pop()
274
+
275
+ raise RuntimeError, "[List.pop]: No se puede extraer elementos de una lista vacía" if empty?()
276
+
277
+ nodo = @head
278
+ if @head.equal?(@tail)
279
+ @head = nil
280
+ @tail = nil
281
+ else
282
+ @head = @head.next_node
283
+ @head.prev_node = nil
284
+ end
285
+
286
+ @size -= 1
287
+
288
+ return nodo.value
289
+
290
+ end
291
+
292
+ # Itera la lista, ejecutando el bloque pasado pasándole como parámetro el valor de cada nodo.
293
+ def each
294
+
295
+ nodo = @head
296
+ until nodo.nil?
297
+ yield nodo.value
298
+ nodo = nodo.next_node
299
+ end
300
+
301
+ end
302
+
303
+ # Devuelve la lista de referencias ordenadas en líneas distintas como cadena.
304
+ def to_s
305
+ s_arr = self.sort()
306
+ return s_arr.join("\n")
307
+ end
308
+
309
+ private :push_empty
310
+
311
+ end
312
+
313
+ end
@@ -0,0 +1,4 @@
1
+ module DLinkedList
2
+ # Versión de la gema.
3
+ VERSION = "0.1.0"
4
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dLinkedList
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - alu0100221879
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: coveralls
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Gema que guarda una lista de referencias bibliográficas (lista doblemente
112
+ enlazada).
113
+ email:
114
+ - alu0100221879@ull.edu.es
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".coveralls.yml"
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - Guardfile
125
+ - LICENSE.txt
126
+ - README.md
127
+ - Rakefile
128
+ - bin/console
129
+ - bin/setup
130
+ - dLinkedList.gemspec
131
+ - html/DLinkedList.html
132
+ - html/DLinkedList/Articulo.html
133
+ - html/DLinkedList/EDocumento.html
134
+ - html/DLinkedList/Libro.html
135
+ - html/DLinkedList/List.html
136
+ - html/DLinkedList/Node.html
137
+ - html/DLinkedList/Referencia.html
138
+ - html/created.rid
139
+ - html/css/fonts.css
140
+ - html/css/rdoc.css
141
+ - html/fonts/Lato-Light.ttf
142
+ - html/fonts/Lato-LightItalic.ttf
143
+ - html/fonts/Lato-Regular.ttf
144
+ - html/fonts/Lato-RegularItalic.ttf
145
+ - html/fonts/SourceCodePro-Bold.ttf
146
+ - html/fonts/SourceCodePro-Regular.ttf
147
+ - html/images/add.png
148
+ - html/images/arrow_up.png
149
+ - html/images/brick.png
150
+ - html/images/brick_link.png
151
+ - html/images/bug.png
152
+ - html/images/bullet_black.png
153
+ - html/images/bullet_toggle_minus.png
154
+ - html/images/bullet_toggle_plus.png
155
+ - html/images/date.png
156
+ - html/images/delete.png
157
+ - html/images/find.png
158
+ - html/images/loadingAnimation.gif
159
+ - html/images/macFFBgHack.png
160
+ - html/images/package.png
161
+ - html/images/page_green.png
162
+ - html/images/page_white_text.png
163
+ - html/images/page_white_width.png
164
+ - html/images/plugin.png
165
+ - html/images/ruby.png
166
+ - html/images/tag_blue.png
167
+ - html/images/tag_green.png
168
+ - html/images/transparent.png
169
+ - html/images/wrench.png
170
+ - html/images/wrench_orange.png
171
+ - html/images/zoom.png
172
+ - html/index.html
173
+ - html/js/darkfish.js
174
+ - html/js/jquery.js
175
+ - html/js/navigation.js
176
+ - html/js/navigation.js.gz
177
+ - html/js/search.js
178
+ - html/js/search_index.js
179
+ - html/js/search_index.js.gz
180
+ - html/js/searcher.js
181
+ - html/js/searcher.js.gz
182
+ - html/table_of_contents.html
183
+ - lib/dLinkedList.rb
184
+ - lib/dLinkedList/dLinkedList.rb
185
+ - lib/dLinkedList/version.rb
186
+ homepage: https://github.com/alu0100221879/prct11
187
+ licenses:
188
+ - MIT
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.4.8
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Gema del módulo DLinkedList.
210
+ test_files: []