gematdd-dibad 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +115 -0
  8. data/Guardfile +82 -0
  9. data/README.md +41 -0
  10. data/Rakefile +11 -0
  11. data/bin/bundle +105 -0
  12. data/bin/console +14 -0
  13. data/bin/htmldiff +29 -0
  14. data/bin/ldiff +29 -0
  15. data/bin/rspec +29 -0
  16. data/bin/setup +8 -0
  17. data/doc/DatosAntropometricos.html +782 -0
  18. data/doc/Etiqueta.html +1339 -0
  19. data/doc/Factor.html +262 -0
  20. data/doc/FactorActFisica.html +136 -0
  21. data/doc/FichaValoracionNutricional.html +857 -0
  22. data/doc/Gematdd.html +133 -0
  23. data/doc/Gematdd/Error.html +124 -0
  24. data/doc/Grasas.html +578 -0
  25. data/doc/Hidratos.html +576 -0
  26. data/doc/Individuo.html +845 -0
  27. data/doc/Lista.html +1281 -0
  28. data/doc/Node.html +409 -0
  29. data/doc/Paciente.html +379 -0
  30. data/doc/PacienteConDatos.html +988 -0
  31. data/doc/PacienteConObesidad.html +342 -0
  32. data/doc/PacienteSinObesidad.html +342 -0
  33. data/doc/_index.html +251 -0
  34. data/doc/class_list.html +51 -0
  35. data/doc/css/common.css +1 -0
  36. data/doc/css/full_list.css +58 -0
  37. data/doc/css/style.css +496 -0
  38. data/doc/file.README.html +118 -0
  39. data/doc/file_list.html +56 -0
  40. data/doc/frames.html +17 -0
  41. data/doc/index.html +118 -0
  42. data/doc/js/app.js +292 -0
  43. data/doc/js/full_list.js +216 -0
  44. data/doc/js/jquery.js +4 -0
  45. data/doc/method_list.html +787 -0
  46. data/doc/top-level-namespace.html +112 -0
  47. data/examples/ejemplo.rb +32 -0
  48. data/gematdd.gemspec +35 -0
  49. data/lib/gematdd.rb +6 -0
  50. data/lib/gematdd/etiqueta/etiqueta.rb +100 -0
  51. data/lib/gematdd/etiqueta/factor.rb +32 -0
  52. data/lib/gematdd/etiqueta/grasas.rb +24 -0
  53. data/lib/gematdd/etiqueta/hidratos.rb +23 -0
  54. data/lib/gematdd/lista/lista.rb +170 -0
  55. data/lib/gematdd/menu/menu.rb +89 -0
  56. data/lib/gematdd/menu/menu.rb~ +95 -0
  57. data/lib/gematdd/paciente/individuo.rb +37 -0
  58. data/lib/gematdd/paciente/paciente.rb +16 -0
  59. data/lib/gematdd/paciente/paciente_con_obesidad.rb +21 -0
  60. data/lib/gematdd/paciente/paciente_datos.rb +69 -0
  61. data/lib/gematdd/paciente/paciente_sin_obesidad.rb +22 -0
  62. data/lib/gematdd/valoracion/datos_antropometricos.rb +37 -0
  63. data/lib/gematdd/valoracion/ficha_valoracion.rb +70 -0
  64. data/lib/gematdd/version.rb +3 -0
  65. metadata +235 -0
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.9.16
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ pathId = "";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+
41
+
42
+ <span class="title">Top Level Namespace</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Top Level Namespace
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ </div>
80
+
81
+ <h2>Defined Under Namespace</h2>
82
+ <p class="children">
83
+
84
+
85
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Factor.html" title="Factor (module)">Factor</a></span>, <span class='object_link'><a href="FactorActFisica.html" title="FactorActFisica (module)">FactorActFisica</a></span>, <span class='object_link'><a href="Gematdd.html" title="Gematdd (module)">Gematdd</a></span>
86
+
87
+
88
+
89
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="DatosAntropometricos.html" title="DatosAntropometricos (class)">DatosAntropometricos</a></span>, <span class='object_link'><a href="Etiqueta.html" title="Etiqueta (class)">Etiqueta</a></span>, <span class='object_link'><a href="FichaValoracionNutricional.html" title="FichaValoracionNutricional (class)">FichaValoracionNutricional</a></span>, <span class='object_link'><a href="Grasas.html" title="Grasas (class)">Grasas</a></span>, <span class='object_link'><a href="Hidratos.html" title="Hidratos (class)">Hidratos</a></span>, <span class='object_link'><a href="Individuo.html" title="Individuo (class)">Individuo</a></span>, <span class='object_link'><a href="Lista.html" title="Lista (class)">Lista</a></span>, <span class='object_link'><a href="Node.html" title="Node (class)">Node</a></span>, <span class='object_link'><a href="Paciente.html" title="Paciente (class)">Paciente</a></span>, <span class='object_link'><a href="PacienteConDatos.html" title="PacienteConDatos (class)">PacienteConDatos</a></span>, <span class='object_link'><a href="PacienteConObesidad.html" title="PacienteConObesidad (class)">PacienteConObesidad</a></span>, <span class='object_link'><a href="PacienteSinObesidad.html" title="PacienteSinObesidad (class)">PacienteSinObesidad</a></span>
90
+
91
+
92
+ </p>
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ </div>
103
+
104
+ <div id="footer">
105
+ Generated on Wed Dec 12 00:08:11 2018 by
106
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
+ 0.9.16 (ruby-2.5.1).
108
+ </div>
109
+
110
+ </div>
111
+ </body>
112
+ </html>
@@ -0,0 +1,32 @@
1
+ require 'lib/gematdd/paciente/paciente_con_obesidad'
2
+ require 'lib/gematdd/paciente/paciente_sin_obesidad'
3
+
4
+ p1 = Paciente.new("David", "Afonso Dorta", 1, "18-11-1998", "Estudiante",
5
+ "Clinica ULL")
6
+ puts p1.to_s
7
+
8
+
9
+ puts "------------------------------\n"
10
+
11
+ datos = DatosAntropometricos.new(50, 1.80, 52, 58)
12
+ p2 = PacienteConDatos.new("David", "Afonso Dorta", 1, "18-11-1998", "Estudiante",
13
+ "Clinica ULL", datos)
14
+ puts p2.to_s
15
+
16
+
17
+ puts "------------------------------\n"
18
+
19
+ datos = DatosAntropometricos.new(150, 1.80, 52, 58)
20
+ p3 = PacienteConObesidad.new("David", "Afonso Dorta", 1, "18-11-1998", "Estudiante",
21
+ "Clinica ULL", datos)
22
+
23
+ puts p3.to_s
24
+
25
+
26
+ puts "------------------------------\n"
27
+
28
+ datos = DatosAntropometricos.new(50, 1.80, 52, 58)
29
+ p4 = PacienteSinObesidad.new("David", "Afonso Dorta", 1, "18-11-1998", "Estudiante",
30
+ "Clinica ULL", datos)
31
+
32
+ puts p4.to_s
data/gematdd.gemspec ADDED
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "gematdd/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gematdd-dibad"
8
+ spec.version = Gematdd::VERSION
9
+ spec.authors = ["David Afonso"]
10
+ spec.email = ["alu0101015255@ull.edu.es"]
11
+
12
+ spec.summary = %q{Gema para las prácticas de LPP}
13
+ spec.description = %q{Gema utilizada durante las prácticas de LPP aprender
14
+ Ruby y los diferentes paradigmas de programación que hay}
15
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1819/tdd-Dibad.git"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib", "lib/gematdd"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "ruby-units"
30
+ spec.add_development_dependency "guard"
31
+ spec.add_development_dependency "guard-rspec"
32
+ spec.add_development_dependency "guard-bundler"
33
+ spec.add_development_dependency "yard"
34
+ spec.add_development_dependency "coveralls"
35
+ end
data/lib/gematdd.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'gematdd/version'
2
+
3
+ module Gematdd
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,100 @@
1
+ require 'ruby-units'
2
+
3
+ require 'etiqueta/grasas'
4
+ require 'etiqueta/hidratos'
5
+ require 'etiqueta/factor'
6
+
7
+ # Etiqueta utilizada en los cálculos del valor nutricional de un alimento.
8
+ # Utiliza las clases Grasa e Hidratos y el modulo Factor para los cálculos.
9
+ class Etiqueta
10
+ include Comparable
11
+
12
+ attr_accessor :nombre, :gramos, :grasas, :hidratos, :proteinas, :sal,
13
+ :fibra_alimentaria, :vitamina_mineral, :porciones
14
+
15
+ def initialize(nombre, gramos, grasas, hidratos, proteinas,
16
+ sal = nil, fibra_alimentaria = nil, vitamina_mineral = nil, porciones = 1)
17
+ @nombre = nombre
18
+ @gramos = Unit.new(gramos).convert_to('g')
19
+ @grasas = grasas
20
+ @hidratos = hidratos
21
+ @proteinas = Unit.new(proteinas).convert_to('g')
22
+ @sal = Unit.new(sal).convert_to('g') unless sal.nil?
23
+ @fibra_alimentaria = Unit.new(fibra_alimentaria).convert_to('g') unless fibra_alimentaria.nil?
24
+ @vitamina_mineral = Unit.new(vitamina_mineral).convert_to('mg') unless vitamina_mineral.nil?
25
+ @porciones = porciones
26
+ end
27
+
28
+ # Devuelve el valor nutricional de un alimento en Kilojulios
29
+ def valor_nutr_kj
30
+ grasas.total * Factor::GRASAS_KJ + hidratos.total * Factor::HIDRATOS_KJ + proteinas *
31
+ Factor::PROTEINAS_KJ
32
+ end
33
+
34
+ # Devuelve el valor nutricional de un alimento en Kilocalorías
35
+ def valor_nutr_kcal
36
+ grasas.total * Factor::GRASAS_KCAL + hidratos.total * Factor::HIDRATOS_KCAL + proteinas *
37
+ Factor::PROTEINAS_KCAL
38
+ end
39
+
40
+ # Calcula la cantidad de gramos que tendrá un nutriente por cada una de las
41
+ # porciones del alimento
42
+ def por_porcion(nutriente)
43
+ (nutriente * (gramos / porciones) / '100 g').round(2).abs unless nutriente.nil?
44
+ end
45
+
46
+ # Cálculo de la Ingesta de Referencia (IR)
47
+ def IR(nutriente)
48
+ case nutriente
49
+ when :valor_energ_kj
50
+ n = valor_nutr_kj / Factor::VALOR_ENERG_KJ_IR
51
+ when :valor_energ_kcal
52
+ n = valor_nutr_kcal / Factor::VALOR_ENERG_KCAL_IR
53
+ when :grasas
54
+ n = grasas.total / Factor::GRASAS_IR
55
+ when :saturadas
56
+ n = grasas.saturadas / Factor::SATURADAS_IR
57
+ when :hidratos
58
+ n = hidratos.total / Factor::HIDRATOS_IR
59
+ when :azucares
60
+ n = hidratos.azucares / Factor::AZUCARES_IR
61
+ when :proteinas
62
+ n = proteinas / Factor::PROTEINAS_IR
63
+ when :sal
64
+ n = sal / Factor::SAL_IR
65
+ when :vitamina_mineral
66
+ n = vitamina_mineral / Factor::VITAMINA_MINERAL_IR unless
67
+ vitamina_mineral.nil?
68
+ end
69
+
70
+ n.convert_to('%').round(2).abs unless n.nil?
71
+ end
72
+
73
+ def <=>(other)
74
+ [sal, proteinas, hidratos, grasas, gramos,
75
+ fibra_alimentaria, vitamina_mineral, porciones] <=>
76
+ [other.sal, other.proteinas, other.hidratos, other.grasas, other.gramos,
77
+ other.fibra_alimentaria, other.vitamina_mineral, other.porciones]
78
+ end
79
+
80
+ def to_s
81
+ "\t--> Etiqueta de Información Nutricional de #{nombre} <--
82
+
83
+ Gramos del producto: #{gramos}\t\t Nº de porciones: #{porciones}
84
+
85
+ \t\t\tPor 100g o 100ml\tIR\t\tPor porcion de #{(gramos / porciones)}\t\tIR
86
+ Valor energetico\t#{valor_nutr_kj} / #{valor_nutr_kcal}\t#{IR(:valor_energ_kj)}\t\t#{por_porcion(valor_nutr_kj)} / #{por_porcion(valor_nutr_kcal)}\t\t#{por_porcion(IR(:valor_energ_kj))}
87
+ Grasas\t\t#{grasas.total}\t\t\t#{IR(:grasas)}\t\t#{por_porcion(grasas.total)}\t\t\t\t#{por_porcion(IR(:grasas))}
88
+ - Saturadas\t\t#{grasas.saturadas}\t\t\t#{IR(:saturadas)}\t\t#{por_porcion(grasas.saturadas)}\t\t\t\t#{por_porcion(IR(:saturadas))}
89
+ - Monoinsaturadas\t#{grasas.monoinsaturadas}\t\t\t-\t\t#{por_porcion(grasas.monoinsaturadas)}\t\t\t\t-
90
+ - Polinsaturadas\t#{grasas.polinsaturadas}\t\t\t-\t\t#{por_porcion(grasas.polinsaturadas)}\t\t\t\t-
91
+ Hidratos\t\t#{hidratos.total}\t\t\t#{IR(:hidratos)}\t\t#{por_porcion(hidratos.total)}\t\t\t\t#{por_porcion(IR(:hidratos))}
92
+ - Azucares\t\t#{hidratos.azucares}\t\t\t#{IR(:azucares)}\t\t#{por_porcion(hidratos.azucares)}\t\t\t\t#{por_porcion(IR(:azucares))}
93
+ - Polialcoholes\t\t#{hidratos.polialcoholes}\t\t-\t\t#{por_porcion(hidratos.polialcoholes)}\t\t\t\t-
94
+ - Almidón\t\t#{hidratos.almidon}\t\t\t-\t\t#{por_porcion(hidratos.almidon)}\t\t\t\t-
95
+ Fibra alimentaria\t#{fibra_alimentaria}\t\t\t-\t\t#{por_porcion(fibra_alimentaria)}\t\t\t\t-
96
+ Proteínas\t\t#{proteinas}\t\t\t#{IR(:proteinas)}\t\t#{por_porcion(proteinas)}\t\t\t\t#{por_porcion(IR(:proteinas))}
97
+ Sal\t\t\t#{sal}\t\t\t#{IR(:sal)}\t\t#{por_porcion(sal)}\t\t\t\t#{por_porcion(IR(:sal))}
98
+ Vitamina/Mineral\t#{vitamina_mineral}\t\t\t#{IR(:vitamina_mineral)}\t\t#{por_porcion(vitamina_mineral)}\t\t\t\t#{por_porcion(IR(:vitamina_mineral))}"
99
+ end
100
+ end
@@ -0,0 +1,32 @@
1
+ # Constantes utilizadas en los cálculos de los valores nutricionales
2
+ module Factor
3
+ GRASAS_KJ = '37 kJ/g'.freeze
4
+ MONOINSATURADAS_KJ = '37 kJ/g'.freeze
5
+ POLINSATURADAS_KJ = '37 kJ/g'.freeze
6
+ HIDRATOS_KJ = '17 kJ/g'.freeze
7
+ POLIALCOHOLES_KJ = '10 kJ/g'.freeze
8
+ ALMIDON_KJ = '17 kJ/g'.freeze
9
+ FIBRA_ALIMENTARIA_KJ = '8 kJ/g'.freeze
10
+ PROTEINAS_KJ = '17 kJ/g'.freeze
11
+ SAL_KJ = '25 kJ/g'.freeze
12
+
13
+ GRASAS_KCAL = '9 kcal/g'.freeze
14
+ MONOINSATURADAS_KCAL = '9 kcal/g'.freeze
15
+ POLINSATURADAS_KCAL = '9 kcal/g'.freeze
16
+ HIDRATOS_KCAL = '4 kcal/g'.freeze
17
+ POLIALCOHOLES_KCAL = '2.4 kcal/g'.freeze
18
+ ALMIDON_KCAL = '4 kcal/g'.freeze
19
+ FIBRA_ALIMENTARIA_KCAL = '2 kcal/g'.freeze
20
+ PROTEINAS_KCAL = '4 kcal/g'.freeze
21
+ SAL_KCAL = '6 kcal/g'.freeze
22
+
23
+ VALOR_ENERG_KJ_IR = '8400 kJ'.freeze
24
+ VALOR_ENERG_KCAL_IR = '2000 kcal'.freeze
25
+ GRASAS_IR = '70 g'.freeze
26
+ SATURADAS_IR = '20 g'.freeze
27
+ HIDRATOS_IR = '260 g'.freeze
28
+ AZUCARES_IR = '90 g'.freeze
29
+ PROTEINAS_IR = '50 g'.freeze
30
+ SAL_IR = '6 g'.freeze
31
+ VITAMINA_MINERAL_IR = '80 mg'.freeze
32
+ end
@@ -0,0 +1,24 @@
1
+ require 'ruby-units'
2
+
3
+ # Agrupa los diferentes tipos de grasas que pueden haber en una etiqueta
4
+ class Grasas
5
+ include Comparable
6
+
7
+ attr_accessor :total, :saturadas, :monoinsaturadas, :polinsaturadas
8
+ def initialize(total, saturadas, monoinsaturadas = nil, polinsaturadas =
9
+ nil)
10
+ @total = Unit.new(total).convert_to('g')
11
+ @saturadas = Unit.new(saturadas).convert_to('g')
12
+ @monoinsaturadas = Unit.new(monoinsaturadas).convert_to('g') unless monoinsaturadas.nil?
13
+ @polinsaturadas = Unit.new(polinsaturadas).convert_to('g') unless polinsaturadas.nil?
14
+ end
15
+
16
+ def <=>(other)
17
+ [total, saturadas, monoinsaturadas, polinsaturadas] <=>
18
+ [other.total, other.saturadas, other.monoinsaturadas, other.polinsaturadas]
19
+ end
20
+
21
+ def to_s
22
+ "#{total}"
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'ruby-units'
2
+
3
+ # Agrupa los diferentes tipos de hidratos que puede tener una etiqueta
4
+ class Hidratos
5
+ include Comparable
6
+
7
+ attr_accessor :total, :azucares, :polialcoholes, :almidon
8
+ def initialize(total, azucares, polialcoholes = nil, almidon = nil)
9
+ @total = Unit.new(total).convert_to('g')
10
+ @azucares = Unit.new(azucares).convert_to('g')
11
+ @polialcoholes = Unit.new(polialcoholes).convert_to('g') unless polialcoholes.nil?
12
+ @almidon = Unit.new(almidon).convert_to('g') unless almidon.nil?
13
+ end
14
+
15
+ def <=>(other)
16
+ [total, azucares, polialcoholes, almidon] <=>
17
+ [other.total, other.azucares, other.polialcoholes, other.almidon]
18
+ end
19
+
20
+ def to_s
21
+ "#{@total}"
22
+ end
23
+ end
@@ -0,0 +1,170 @@
1
+ # Nodos utilizados por la lista (Unidad mínima)
2
+ Node = Struct.new(:value, :next, :prev)
3
+
4
+ # Implementación de una Lista Doblemente Enlazada
5
+ class Lista
6
+ include Enumerable
7
+ include Comparable
8
+
9
+ attr_reader :head, :tail, :size
10
+
11
+ def initialize(*values)
12
+ @size = 0
13
+ values.each{|val| push_back(val)}
14
+ end
15
+
16
+ # Comprueba si la lista está vacía
17
+ def empty?
18
+ @size.zero?
19
+ end
20
+
21
+ # Limpia la lista completamente
22
+ def clear
23
+ @head = @tail = nil
24
+ @size = 0
25
+ end
26
+
27
+ def front
28
+ @head.value unless @head == nil
29
+ end
30
+
31
+ def back
32
+ @tail.value unless @tail == nil
33
+ end
34
+
35
+ # Inserta elementos en la lista desde el frente
36
+ def push_front(value)
37
+ node = Node.new(value, @head, nil)
38
+
39
+ if empty?
40
+ @head = @tail = node
41
+ else
42
+ @head.prev = node
43
+ @head = node
44
+ end
45
+
46
+ @size += 1
47
+ end
48
+
49
+ # Elimina elementos en la lista desde el frente
50
+ def pop_front
51
+ node = @head
52
+
53
+ if @size == 1
54
+ node = @head
55
+ @head = @tail = nil
56
+ else
57
+ @head.next.prev = nil
58
+ @head = @head.next
59
+ node.next = nil
60
+ end
61
+
62
+ @size -= 1
63
+ node
64
+ end
65
+
66
+ # Inserta elementos en la lista desde detrás
67
+ def push_back(value)
68
+ node = Node.new(value, nil, @tail)
69
+ if empty?
70
+ @head = @tail = node
71
+ else
72
+ @tail.next = node
73
+ @tail = node
74
+ end
75
+
76
+ @size += 1
77
+ end
78
+
79
+ # Elimina elementos en la lista desde detrás
80
+ def pop_back
81
+ node = @tail
82
+ if @size == 1
83
+ node = @tail
84
+ @head = @tail = nil
85
+ else
86
+ @tail.prev.next = nil
87
+ @tail = @tail.prev
88
+ node.prev = nil
89
+ end
90
+
91
+ @size -= 1
92
+ node
93
+ end
94
+
95
+ # Inserta un valor después del nodo especificado
96
+ def insert(node, value)
97
+ inserted = Node.new(value, node.next, node)
98
+ node.next.prev = inserted
99
+ node.next = inserted
100
+
101
+ @size += 1
102
+ inserted
103
+ end
104
+
105
+ def remove(value)
106
+ if @size == 1 && @head.value == value
107
+ @head = @tail = nil
108
+ else
109
+ node = @head
110
+ while node
111
+ if node.value == value
112
+ erase(node)
113
+ break
114
+ end
115
+ node = node.next
116
+ end
117
+ end
118
+ end
119
+
120
+ # Elimina el nodo especificado
121
+ def erase(node)
122
+ if @size == 1 && @head == node
123
+ @head = @tail = nil
124
+ @size -= 1
125
+ else
126
+ if @size > 1
127
+ if @head == node
128
+ pop_front
129
+ elsif @tail == node
130
+ pop_back
131
+ else
132
+ node.next.prev = node.prev
133
+ node.prev.next = node.next
134
+ @size -= 1
135
+ end
136
+ end
137
+ end
138
+
139
+ node.next = nil
140
+ node.prev = nil
141
+ node
142
+ end
143
+
144
+ # Recorre la lista doblemente enlazada de principio a fin
145
+ def each
146
+ current = @head
147
+ while current
148
+ yield current.value
149
+ current = current.next
150
+ end
151
+ end
152
+
153
+ # Ordena la lista (sobre ella misma)
154
+ def for_sort!
155
+ swapped = true
156
+
157
+ while swapped
158
+ node = @head
159
+ swapped = false
160
+ while node && !node.next.nil?
161
+ if node.next.value < node.value
162
+ node.value, node.next.value = node.next.value, node.value
163
+ swapped = true
164
+ end
165
+ node = node.next
166
+ end
167
+ node = @head if swapped
168
+ end
169
+ end
170
+ end