gema_menu_alu0100894325 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50a1ac9057a4eecd8515f67d5773d6b4ca8fa071
4
+ data.tar.gz: 74b4ffda7b4db4f41004de47c4b1b9f144aaa88c
5
+ SHA512:
6
+ metadata.gz: 3d0076f12eea06c18aae14a037d5d2cda9b1b1da3da9acfd83d98c5a61c8a1f8be900f62da4d160532f0d25b18aec2dd272b44230951a5a755b2041f15e7d670
7
+ data.tar.gz: dc64757a574231fbcb4aec6aa0e497a6e21aad6dbd7f8ed89c1961d3179f75d304d866d5425b019875bd57154adeffa55e94b4f75d282bbc0933eccd964cf91d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alu0100894325@ull.edu.es. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in prct06.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,82 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :bundler do
19
+ require 'guard/bundler'
20
+ require 'guard/bundler/verify'
21
+ helper = Guard::Bundler::Verify.new
22
+
23
+ files = ['Gemfile']
24
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
25
+
26
+ # Assume files are symlinked from somewhere
27
+ files.each { |file| watch(helper.real_path(file)) }
28
+ end
29
+
30
+ # Note: The cmd option is now required due to the increasing number of ways
31
+ # rspec may be run, below are examples of the most common uses.
32
+ # * bundler: 'bundle exec rspec'
33
+ # * bundler binstubs: 'bin/rspec'
34
+ # * spring: 'bin/rspec' (This will use spring if running and you have
35
+ # installed the spring binstubs per the docs)
36
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
37
+ # * 'just' rspec: 'rspec'
38
+
39
+ guard :rspec, cmd: "bundle exec rspec" do
40
+ require "guard/rspec/dsl"
41
+ dsl = Guard::RSpec::Dsl.new(self)
42
+
43
+ # Feel free to open issues for suggestions and improvements
44
+
45
+ # RSpec files
46
+ rspec = dsl.rspec
47
+ watch(rspec.spec_helper) { rspec.spec_dir }
48
+ watch(rspec.spec_support) { rspec.spec_dir }
49
+ watch(rspec.spec_files)
50
+
51
+ # Ruby files
52
+ ruby = dsl.ruby
53
+ dsl.watch_spec_files_for(ruby.lib_files)
54
+
55
+ # Rails files
56
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
57
+ dsl.watch_spec_files_for(rails.app_files)
58
+ dsl.watch_spec_files_for(rails.views)
59
+
60
+ watch(rails.controllers) do |m|
61
+ [
62
+ rspec.spec.call("routing/#{m[1]}_routing"),
63
+ rspec.spec.call("controllers/#{m[1]}_controller"),
64
+ rspec.spec.call("acceptance/#{m[1]}")
65
+ ]
66
+ end
67
+
68
+ # Rails config changes
69
+ watch(rails.spec_helper) { rspec.spec_dir }
70
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
71
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
72
+
73
+ # Capybara features specs
74
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
75
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
76
+
77
+ # Turnip features and steps
78
+ watch(%r{^spec/acceptance/(.+)\.feature$})
79
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
80
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
81
+ end
82
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Pamela
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Prct06
2
+
3
+ Clase Dieta para la práctica de laboratorio 6.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'prct06'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install prct06
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/prct06. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :p10spec
9
+
10
+ desc "Ejecutar las espectativas de la práctica 10"
11
+ task :p10spec do
12
+ sh "rspec -I. spec/prct10_spec.rb"
13
+ end
14
+
15
+ desc "Ejecutar las espectativas de la práctica 9"
16
+ task :p9spec do
17
+ sh "rspec -I. spec/prct09_spec.rb"
18
+ end
19
+
20
+ desc "Ejecutar las espectativas de la práctica 8"
21
+ task :p8spec do
22
+ sh "rspec -I. spec/prct08_spec.rb"
23
+ end
24
+
25
+ desc "Ejecutar las espectativas de la clase Lista"
26
+ task :p7spec do
27
+ sh "rspec -I. spec/prct07_spec.rb"
28
+ end
29
+
30
+ desc "Ejecutar las espectativas de la clase Dieta"
31
+ task :spec do
32
+ sh "rspec -I. spec/prct06_spec.rb"
33
+ end
34
+
35
+ desc "Ejecutar con documentación"
36
+ task :doc do
37
+ sh "rspec -I. spec/prct06_spec.rb --format documentation"
38
+ end
data/bin/bundler ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'bundler' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("bundler", "bundler")
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "prct06"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/htmldiff ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'htmldiff' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("diff-lcs", "htmldiff")
data/bin/ldiff ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'ldiff' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("diff-lcs", "ldiff")
data/bin/rake ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
data/bin/rspec ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rspec' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,56 @@
1
+ #Clase Dieta que representa un menú dietético genérico.
2
+ class Dieta
3
+
4
+
5
+ #Módulo Comparable
6
+ include Comparable
7
+
8
+ #Titulo de la dieta
9
+ attr_accessor :titulo
10
+ #Ingesta diaria de la dieta
11
+ attr_accessor :ing_diaria
12
+ #Platos que constituyen la dieta
13
+ attr_accessor :platos
14
+ #Valor calórico total de la dieta
15
+ attr_accessor :vct
16
+ #Porcentaje de proteínas de un conjunto de platos
17
+ attr_accessor :prot
18
+ #Porcentaje de grasas de un conjunto de platos
19
+ attr_accessor :grasas
20
+ #Porcentaje de hidratos de carbono de un conjunto de platos
21
+ attr_accessor :carbo
22
+
23
+
24
+ #Inicializa los atributos
25
+ def initialize(titulo, ing_diaria, platos, vct, prot, grasas, carbo)
26
+
27
+ @titulo = titulo
28
+ @ing_diaria = ing_diaria
29
+ @platos = platos
30
+ @vct = vct
31
+ @prot = prot
32
+ @grasas = grasas
33
+ @carbo = carbo
34
+
35
+ end
36
+
37
+ #Imprime la dieta con el formato adecuado
38
+ def to_s
39
+
40
+ title = "#{@titulo} (#{@ing_diaria})\n"
41
+
42
+ for i in 0..@platos.size-1
43
+ title+="-#{@platos[i][0]}, #{@platos[i][1]}, #{@platos[i][2]}\n"
44
+ end
45
+
46
+ title += "V.C.T. | %\t#{@vct} | #{@prot} - #{@grasas} - #{@carbo}"
47
+ end
48
+
49
+ #Permite a los objetos de la clase Dieta (o sus hijas) compararse con otros objetos de la clase Dieta (o sus hijas)
50
+ def <=> (another)
51
+
52
+ vct.delete(' kcal').to_f <=> another.vct.delete(' kcal').to_f
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,94 @@
1
+ #Clase Dieta_dsl.
2
+ class Dieta_dsl
3
+
4
+ #Módulo Comparable
5
+ include Comparable
6
+
7
+ #Etiqueta de la dieta
8
+ attr_accessor :etiqueta
9
+ #Titulo de la dieta
10
+ attr_accessor :titulo
11
+ #Ingesta diaria de la dieta
12
+ attr_accessor :ing_diaria
13
+ #Platos que constituyen la dieta
14
+ attr_accessor :platos
15
+ #Valores de los porcentajes de la dieta
16
+ attr_accessor :porcentajes
17
+
18
+ #Inicializa los atributos
19
+ def initialize(etiqueta, &block)
20
+
21
+ @etiqueta = etiqueta
22
+ @titulo = "SIN TITULO"
23
+ @ing_diaria = []
24
+ @platos = []
25
+ @porcentajes = []
26
+
27
+ if block_given?
28
+ if block.arity == 1
29
+ yield self
30
+ else
31
+ instance_eval(&block)
32
+ end
33
+ end
34
+ end
35
+
36
+ #Titulo
37
+ def tit(name)
38
+
39
+ @titulo = name
40
+ end
41
+
42
+ #Ingesta diaria
43
+ def i_d(options = {})
44
+
45
+ i_d = []
46
+ i_d << "#{options[:min]}" if options[:min]
47
+ i_d << "#{options[:max]}" if options[:max]
48
+
49
+ @ing_diaria = i_d
50
+ end
51
+
52
+ #Platos
53
+ def plat(options = {})
54
+
55
+ plat = []
56
+ plat << "#{options[:descripcion]}" if options[:descripcion]
57
+ plat << "#{options[:porcion]}" if options[:porcion]
58
+ plat << "#{options[:gramos]}" if options[:gramos]
59
+
60
+ @platos << plat
61
+ end
62
+
63
+ #Porcentajes
64
+ def porc(options = {})
65
+
66
+ porc = []
67
+ porc << "#{options[:vct]}" if options[:vct]
68
+ porc << "#{options[:proteinas]}" if options[:proteinas]
69
+ porc << "#{options[:grasas]}" if options[:grasas]
70
+ porc << "#{options[:hidratos]}" if options[:hidratos]
71
+
72
+ @porcentajes = porc
73
+ end
74
+
75
+ #Imprime la dieta con el formato adecuado
76
+ def to_s
77
+
78
+ title = "#{@etiqueta}\n#{@titulo} (#{@ing_diaria[0]}% - #{@ing_diaria[1]}%)\n"
79
+
80
+ for i in 0..@platos.size-1
81
+ title+="-#{@platos[i][0]}, #{@platos[i][1]}, #{@platos[i][2]} g\n"
82
+ end
83
+
84
+ title += "V.C.T. | %\t#{@porcentajes[0]} kcal | #{@porcentajes[1]}% - #{@porcentajes[2]}% - #{@porcentajes[3]}%"
85
+ end
86
+
87
+ #Permite a los objetos de la clase (o sus hijas) compararse con otros objetos de la clase (o sus hijas)
88
+ def <=> (another)
89
+
90
+ @porcentajes[0].to_f <=> another.porcentajes[0].to_f
91
+
92
+ end
93
+
94
+ end
@@ -0,0 +1,22 @@
1
+ #Clase DietaAlim que representa un menú dietético que se clasifica por grupo de alimentos.
2
+ #Hereda de la clase Dieta.
3
+ class DietaAlim < Dieta
4
+
5
+ #Grupo de alimentos al que pertenece el menú
6
+ attr_reader :alim
7
+
8
+ #Inicializa los atributos llamando al initialize de la clase madre Dieta e inicializando los atributos propios de esta clase
9
+ def initialize(titulo, ing_diaria, platos, vct, prot, grasas, carbo, alim)
10
+
11
+ super(titulo, ing_diaria, platos, vct, prot, grasas, carbo)
12
+ @alim=alim
13
+ end
14
+
15
+ #Muestra el menú usando el to_s de la clase madre e imprimiendo el nuevo atributo
16
+ def to_s
17
+
18
+ super + "\n#{@alim}"
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ #Clase DietaEdad que representa un menú dietético que se clasifica por grupo de edad.
2
+ #Hereda de la clase Dieta.
3
+ class DietaEdad < Dieta
4
+
5
+ #Grupo de edad al que pertenece el menú
6
+ attr_reader :edad
7
+
8
+ #Inicializa los atributos llamando al initialize de la clase madre Dieta e inicializando los atributos propios de esta clase
9
+ def initialize(titulo, ing_diaria, platos, vct, prot, grasas, carbo, edad)
10
+
11
+ super(titulo, ing_diaria, platos, vct, prot, grasas, carbo)
12
+ @edad=edad
13
+ end
14
+
15
+ #Muestra el menú usando el to_s de la clase madre e imprimiendo el nuevo atributo
16
+ def to_s
17
+
18
+ super + "\n#{@edad}"
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,66 @@
1
+
2
+ #Struct que representa un nodo de una lista simplemente enlazada, con el valor que contiene y un puntero al siguiente nodo de la lista
3
+ Node = Struct.new(:value, :next)
4
+
5
+ #Clase Lista que representa una lista simplemente enlazada.
6
+ class Lista
7
+
8
+ #Puntero al nodo cabeza de la lista
9
+ attr_reader :head
10
+
11
+ #Inicializa la cabeza a nil, para poder tener una lista vacía, sin nodos
12
+ def initialize
13
+
14
+ @head = nil
15
+
16
+ end
17
+
18
+ #Permite introducir un elemento de cualquier tipo en la lista, e internamente se creará un nodo y se meterá por la cabeza
19
+ def push (*elementos)
20
+
21
+ elementos.each do |i|
22
+
23
+ nodo = Node.new(i, @head)
24
+ @head = nodo
25
+ end
26
+
27
+ end
28
+
29
+ #Permite sacar un elemento de la lista por la cabeza, devolviendo el valor del nodo y no el nodo en sí, y eliminando el nodo
30
+ def pop
31
+
32
+ nodo = @head
33
+ @head = @head.next
34
+ return nodo.value
35
+
36
+ end
37
+
38
+ #Indica si la lista está vacía o no
39
+ def is_empty?
40
+
41
+ if @head==nil
42
+ return true
43
+ else
44
+ return false
45
+
46
+ end
47
+ end
48
+
49
+ #Imprime la lista con el formato adecuado, elemento por elemento, desde la cabeza en adelante
50
+ def to_s
51
+
52
+ nodo = @head
53
+ cadena = ""
54
+ cont = 1
55
+
56
+ while nodo!=nil do
57
+ cadena += "#{cont}) #{nodo.value}\n"
58
+ nodo = nodo.next
59
+ cont+=1
60
+ end
61
+
62
+ cadena
63
+ end
64
+
65
+
66
+ end
@@ -0,0 +1,143 @@
1
+ #Struct que representa un nodo de una lista doblemente enlazada, con el valor que contiene, un puntero al siguiente nodo de la lista y otro al anterior
2
+ NodeLD = Struct.new(:value, :prev, :next)
3
+
4
+ #Clase ListaDoble que representa una lista doblemente enlazada.
5
+ class ListaDoble
6
+
7
+ #Módulo Enumerable
8
+ include Enumerable
9
+
10
+ #Puntero al nodo cabeza de la lista
11
+ attr_reader :head
12
+ #Puntero al nodo cola de la lista
13
+ attr_reader :tail
14
+
15
+ #Inicializa la cabeza y la cola a nil, para poder tener una lista vacía, sin nodos
16
+ def initialize
17
+
18
+ @head = nil
19
+ @tail = nil
20
+
21
+ end
22
+
23
+ #Inserta un elemento de cualquier tipo por la cola, creando un nodo internamente
24
+ def insert_tail (*elementos)
25
+
26
+ elementos.each do |i|
27
+
28
+ nodo = NodeLD.new(i, nil, @tail)
29
+
30
+ if (@tail != nil)
31
+ @tail.prev = nodo
32
+ @tail = nodo
33
+
34
+ else
35
+ @tail = nodo
36
+ @head = nodo
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+ #Inserta un elemento de cualquier tipo por la cabeza, creando un nodo internamente
44
+ def insert_head (*elementos)
45
+
46
+ elementos.each do |i|
47
+
48
+ nodo = NodeLD.new(i, @head, nil)
49
+
50
+ if (@head != nil)
51
+ @head.next = nodo
52
+ @head = nodo
53
+ else
54
+ @tail = nodo
55
+ @head = nodo
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ #Extrae un elemento por la cabeza, devolviendo el valor en sí y no el nodo (que se elimina)
63
+ def extract_head
64
+
65
+ if (@head!=nil)
66
+
67
+ nodo = head
68
+ @head = @head.prev
69
+
70
+ if (@head != nil)
71
+ @head.next=nil
72
+ else
73
+ @tail=nil
74
+ end
75
+
76
+ return nodo.value
77
+ else
78
+ return nil
79
+ end
80
+
81
+ end
82
+
83
+ #Extrae un elemento por la cola, devolviendo el valor en sí y no el nodo (que se elimina)
84
+ def extract_tail
85
+
86
+ if (@tail!=nil)
87
+
88
+ nodo = @tail
89
+ @tail = @tail.next
90
+
91
+ if (@tail != nil)
92
+ @tail.prev=nil
93
+ else
94
+ @head=nil
95
+ end
96
+
97
+ return nodo.value
98
+ else
99
+ return nil
100
+ end
101
+
102
+ end
103
+
104
+ #Indica si la lista está vacía o no
105
+ def is_empty?
106
+
107
+ if (@head==nil)&&(@tail==nil)
108
+ return true
109
+ else
110
+ return false
111
+
112
+ end
113
+ end
114
+
115
+ #Imprime la lista doblemente enlazada con el formato adecuado, elemento por elemento, desde la cola en adelante
116
+ def to_s
117
+
118
+ nodo = @tail
119
+ cadena = ""
120
+ cont = 1
121
+
122
+ while nodo!=nil do
123
+ cadena += "#{cont}) #{nodo.value}\n"
124
+ nodo = nodo.next
125
+ cont+=1
126
+ end
127
+
128
+ cadena
129
+ end
130
+
131
+ #Recorre la lista, permite utilizar las funciones del módulo Enumerable
132
+ def each
133
+
134
+ nodo=@head
135
+
136
+ while nodo!=nil do
137
+ yield nodo.value
138
+ nodo=nodo.prev
139
+ end
140
+
141
+ end
142
+
143
+ end
@@ -0,0 +1,5 @@
1
+ #Versión del proyecto
2
+ module Prct06
3
+ #Version actual
4
+ VERSION = "0.1.0"
5
+ end
data/lib/prct06.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "prct06/version"
2
+ require "prct06/dieta.rb"
3
+ require "prct06/dietaedad.rb"
4
+ require "prct06/dietaalim.rb"
5
+ require "prct06/lista.rb"
6
+ require "prct06/listadoble.rb"
7
+ require "prct06/dieta_dsl.rb"
8
+
9
+ module Prct06
10
+ # Your code goes here...
11
+ end
data/prct06.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'prct06/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gema_menu_alu0100894325"
8
+ spec.version = Prct06::VERSION
9
+ spec.authors = ["Pamela"]
10
+ spec.email = ["alu0100894325@ull.edu.es"]
11
+
12
+ spec.summary = "Gema para las prácticas de laboratorio 6, 7, 8, 9 y 10"
13
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1617/menu-dietetico-alu0100894325"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ #if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ #else
21
+ # raise "RubyGems 2.0 or newer is required to protect against " \
22
+ # "public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "guard"
36
+ spec.add_development_dependency "guard-rspec"
37
+ spec.add_development_dependency "guard-bundler"
38
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gema_menu_alu0100894325
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pamela
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-14 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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
+ description:
98
+ email:
99
+ - alu0100894325@ull.edu.es
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - CODE_OF_CONDUCT.md
108
+ - Gemfile
109
+ - Guardfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/bundler
114
+ - bin/console
115
+ - bin/htmldiff
116
+ - bin/ldiff
117
+ - bin/rake
118
+ - bin/rspec
119
+ - bin/setup
120
+ - lib/prct06.rb
121
+ - lib/prct06/dieta.rb
122
+ - lib/prct06/dieta_dsl.rb
123
+ - lib/prct06/dietaalim.rb
124
+ - lib/prct06/dietaedad.rb
125
+ - lib/prct06/lista.rb
126
+ - lib/prct06/listadoble.rb
127
+ - lib/prct06/version.rb
128
+ - prct06.gemspec
129
+ homepage: https://github.com/ULL-ESIT-LPP-1617/menu-dietetico-alu0100894325
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.5.1
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Gema para las prácticas de laboratorio 6, 7, 8, 9 y 10
153
+ test_files: []