Dieta-alu0100845235 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Dieta.gemspec +41 -0
- data/Gemfile +5 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +13 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/Dieta.rb +13 -0
- data/lib/Dieta/lista.rb +124 -0
- data/lib/Dieta/menu.rb +102 -0
- data/lib/Dieta/menu_alimentos.rb +33 -0
- data/lib/Dieta/menu_edad.rb +32 -0
- data/lib/Dieta/nodo.rb +4 -0
- data/lib/Dieta/plato.rb +70 -0
- data/lib/Dieta/version.rb +4 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c9868b7898b750beda01b4d38e3dfc72c4279af7
|
4
|
+
data.tar.gz: f088594dd8c0fb2f50b22bd40ab9ee7e6778d8a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 257e728765a77a28d0b0688d372697ef8d13fbcdbc71edc741e09135a418e4ced382c38ff8593becaffec2b6a6aa832fc1c24fd8eb72e2c13745f28997fd43c3
|
7
|
+
data.tar.gz: e39cd5411ab0af104259e7a9e0080d923b8f584cf82df45beaabec6e19348474f98e5a117d81a8291477bf0839bd7d87a8f7ca2554164ae107e113441100c1a3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Dieta.gemspec
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'Dieta/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "Dieta-alu0100845235"
|
8
|
+
spec.version = Dieta::VERSION
|
9
|
+
spec.authors = ["Ruyman Rodriguez Martin"]
|
10
|
+
spec.email = ["alu0100845235@ull.edu.es"]
|
11
|
+
|
12
|
+
spec.summary = ""
|
13
|
+
spec.description = "Permite las definiciones de menús dietéticos diarios y semanales"
|
14
|
+
spec.homepage = "https://github.com/ULL-ESIT-LPP-1617/menu-dietetico-alu0100845235"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = ""
|
21
|
+
#else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
#end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
|
37
|
+
spec.add_development_dependency "guard"
|
38
|
+
spec.add_development_dependency "guard-rspec"
|
39
|
+
spec.add_development_dependency "guard-bundler"
|
40
|
+
|
41
|
+
end
|
data/Gemfile
ADDED
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 Ruyman Rodriguez
|
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,13 @@
|
|
1
|
+
# Práctica 11: DSL - Menú Dietético
|
2
|
+
|
3
|
+
- Implementar las clases usando DSL (Domnain Specific Language)
|
4
|
+
|
5
|
+
## Desarrollador
|
6
|
+
|
7
|
+
* Ruymán Rodríguez Martín (alu0100845235@ull.edu.es)
|
8
|
+
|
9
|
+
## License
|
10
|
+
|
11
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
12
|
+
|
13
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "Dieta"
|
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/setup
ADDED
data/lib/Dieta.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "Dieta/version"
|
2
|
+
|
3
|
+
# Aplicación que representa listas de menús
|
4
|
+
#
|
5
|
+
# @author Ruymán Rodríguez Martín <alu0100845235@ull.edu.es>
|
6
|
+
module Dieta
|
7
|
+
require "Dieta/plato.rb"
|
8
|
+
require "Dieta/menu.rb"
|
9
|
+
require "Dieta/menu_alimentos.rb"
|
10
|
+
require "Dieta/menu_edad.rb"
|
11
|
+
require "Dieta/nodo.rb"
|
12
|
+
require "Dieta/lista.rb"
|
13
|
+
end
|
data/lib/Dieta/lista.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Lista doblemente enlazada
|
4
|
+
#
|
5
|
+
# @author Ruymán Rodríguez Martín <alu0100845235@ull.edu.es>
|
6
|
+
#
|
7
|
+
# @attr_reader [Nodo] front el principio de la lista
|
8
|
+
# @attr_reader [Nodo] end el final de la lista
|
9
|
+
# @attr_reader [Fixnum] size el tamaño de la lista
|
10
|
+
class Lista
|
11
|
+
include Enumerable
|
12
|
+
attr_reader :front, :end, :size
|
13
|
+
|
14
|
+
# Constructor
|
15
|
+
# @param elements [Object] los elementos a insertar
|
16
|
+
def initialize (*elements)
|
17
|
+
@size = 0
|
18
|
+
@front = Nodo.new(nil, nil, nil)
|
19
|
+
@end = @front
|
20
|
+
push_back(*elements)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Inserta los elementos al final de la lista
|
24
|
+
# @param elements [Object] los elementos a insertar, como si lo hicieras uno a uno
|
25
|
+
def push_back (*elements)
|
26
|
+
elements.each do |element|
|
27
|
+
nodo = Nodo.new(element, nil, nil)
|
28
|
+
if !@end.value
|
29
|
+
# La lista esta vacia
|
30
|
+
@front = nodo
|
31
|
+
@end = @front
|
32
|
+
else
|
33
|
+
# La lista no está vacia
|
34
|
+
@end.next = nodo
|
35
|
+
nodo.previous = @end
|
36
|
+
@end = nodo
|
37
|
+
end
|
38
|
+
@size += 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Inserta los elementos al principio de la lista, como si lo hicieras uno a uno
|
43
|
+
# @param elements [Object] los elementos a insertar
|
44
|
+
def push_front (*elements)
|
45
|
+
elements.each do |element|
|
46
|
+
nodo = Nodo.new(element, nil, nil)
|
47
|
+
if !@front.value
|
48
|
+
# La lista esta vacia
|
49
|
+
@front = nodo
|
50
|
+
@end = @front
|
51
|
+
else
|
52
|
+
# La lista no está vacia
|
53
|
+
@front.previous = nodo
|
54
|
+
nodo.next = @front
|
55
|
+
@front = nodo
|
56
|
+
end
|
57
|
+
@size += 1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Devuelve el objeto de la posición indicada
|
62
|
+
# @param position [Fixnum] número de posición
|
63
|
+
# @return [Object, nil] el objeto o nil si no existe objeto en la posición
|
64
|
+
def get_pos (position)
|
65
|
+
if @size > position
|
66
|
+
pos = 0
|
67
|
+
aux = @front
|
68
|
+
while pos < position
|
69
|
+
aux = aux.next
|
70
|
+
pos += 1
|
71
|
+
end
|
72
|
+
aux.value
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Extrae el objeto al inicio de la lista
|
77
|
+
# @return [Object, nil] el objeto o nil si la lista esta vacia
|
78
|
+
def pop_front
|
79
|
+
if @front.value
|
80
|
+
value = @front.value
|
81
|
+
if @front.next
|
82
|
+
@front = @front.next
|
83
|
+
@front.previous = nil
|
84
|
+
else
|
85
|
+
@front = Nodo.new(nil, nil, nil)
|
86
|
+
@end = @front
|
87
|
+
end
|
88
|
+
@size -= 1
|
89
|
+
value
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Extrae el objeto al final de la lista
|
94
|
+
# @return [Object, nil] el objeto o nil si la lista esta vacia
|
95
|
+
def pop_back
|
96
|
+
if @end.value
|
97
|
+
value = @end.value
|
98
|
+
if @end.previous
|
99
|
+
@end = @end.previous
|
100
|
+
@end.next = nil
|
101
|
+
|
102
|
+
if !@end.previous
|
103
|
+
# Si es el ultimo elemento, actualizamos la cabeza
|
104
|
+
@front = @end
|
105
|
+
end
|
106
|
+
else
|
107
|
+
@front = Nodo.new(nil, nil, nil)
|
108
|
+
@end = @front
|
109
|
+
end
|
110
|
+
@size -= 1
|
111
|
+
value
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Implementación de each para mixin Enumerable
|
116
|
+
def each
|
117
|
+
return nil unless @size > 0
|
118
|
+
aux = @front
|
119
|
+
until aux.nil?
|
120
|
+
yield aux.value
|
121
|
+
aux = aux.next
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/lib/Dieta/menu.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# Menú dietético compuesto por varios platos
|
5
|
+
#
|
6
|
+
# @author Ruymán Rodríguez Martín <alu0100845235@ull.edu.es>
|
7
|
+
#
|
8
|
+
# @attr_reader [String] titulo Título del menú
|
9
|
+
# @attr_reader [String] porcentaje_diario Porcentaje diario
|
10
|
+
# @attr_reader [Array<Plato>] platos Platos que componen el menu
|
11
|
+
# @attr_reader [Float] vct Valor calórico total
|
12
|
+
# @attr_reader [Fixnum] porcentaje_proteinas Porcentaje de proteinas que contiene
|
13
|
+
# @attr_reader [Fixnum] porcentaje_grasas Procentaje de grasas que contiene
|
14
|
+
# @attr_reader [Fixnum] porcentaje_hidratos Porcentaje de hidratos que contiene
|
15
|
+
|
16
|
+
class Menu
|
17
|
+
include Comparable
|
18
|
+
attr_reader :titulo, :porcentaje_diario, :platos, :vct, :porcentaje_proteinas, :porcentaje_grasas, :porcentaje_hidratos
|
19
|
+
|
20
|
+
# Constructor
|
21
|
+
# @param &block [Block] Bloque
|
22
|
+
def initialize (&block)
|
23
|
+
@platos = []
|
24
|
+
|
25
|
+
if block_given?
|
26
|
+
# Recibimos un bloque
|
27
|
+
if block.arity == 1
|
28
|
+
yield self
|
29
|
+
else
|
30
|
+
instance_eval &block
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Asigna el título del menú
|
36
|
+
# @param valor [String] titulo
|
37
|
+
def title(valor)
|
38
|
+
raise ArgumentError.new("PEl titulo no es un String") if !valor.instance_of?(String)
|
39
|
+
@titulo = valor
|
40
|
+
end
|
41
|
+
|
42
|
+
# Inserta un plato
|
43
|
+
def plato(options = {})
|
44
|
+
pl = Plato.new do
|
45
|
+
description options[:descripcion] if options[:descripcion]
|
46
|
+
porcion options[:porcion] if options[:porcion]
|
47
|
+
cantidad options[:cantidad] if options[:cantidad]
|
48
|
+
end
|
49
|
+
|
50
|
+
@platos << pl
|
51
|
+
end
|
52
|
+
|
53
|
+
# Inserta los porcentajes
|
54
|
+
def porcentajes(options = {})
|
55
|
+
raise ArgumentError.new("Valor de V.C.T. no válido") if options[:vct] && !options[:vct].instance_of?(Float)
|
56
|
+
raise ArgumentError.new("Valor de porcentaje de proteinas no válido") if options[:proteinas] && !options[:proteinas].instance_of?(Fixnum)
|
57
|
+
raise ArgumentError.new("Valor de porcentaje de hidratos no válido") if options[:hidratos] && !options[:hidratos].instance_of?(Fixnum)
|
58
|
+
raise ArgumentError.new("Valor de porcentaje de grasas no válido") if options[:grasas] && !options[:grasas].instance_of?(Fixnum)
|
59
|
+
@vct = options[:vct] if options[:vct]
|
60
|
+
@porcentaje_proteinas = options[:proteinas] if options[:proteinas]
|
61
|
+
@porcentaje_hidratos = options[:hidratos] if options[:hidratos]
|
62
|
+
@porcentaje_grasas = options[:grasas] if options[:grasas]
|
63
|
+
end
|
64
|
+
|
65
|
+
# Asigna el porcentaje diario
|
66
|
+
# @param cantidad [String] porcentaje diario
|
67
|
+
def ingesta(cantidad)
|
68
|
+
raise ArgumentError.new("Porcentaje diario no es un String") if !cantidad.instance_of?(String)
|
69
|
+
@porcentaje_diario = cantidad
|
70
|
+
end
|
71
|
+
|
72
|
+
# Devuelve el Plato en la posición indicada
|
73
|
+
# @return [Plato, nil] el plato o nil si no existe plato en la posición indicada
|
74
|
+
def get_plato (posicion)
|
75
|
+
if @platos.length > 0 && posicion.instance_of?(Fixnum) && posicion > -1
|
76
|
+
@platos[posicion]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Devuelve cadena de texto que representa al menú
|
81
|
+
def to_s
|
82
|
+
s = "#{@titulo.upcase} (#{@porcentaje_diario}%)\n"
|
83
|
+
@platos.each do |plato|
|
84
|
+
s << "- #{plato.to_s}"
|
85
|
+
end
|
86
|
+
s << "V.C.T | %\t#{@vct.round(1)} kcal | #{@porcentaje_proteinas}% - #{@porcentaje_grasas}% - #{@porcentaje_hidratos}%\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
# Función de comparación para Mixin Comparable
|
90
|
+
def <=> (other)
|
91
|
+
# devolvemos nil si no son del tipo Menu
|
92
|
+
return nil unless other.is_a? Menu
|
93
|
+
# realizamos las comparaciones necesarias
|
94
|
+
return @titulo <=> other.titulo unless @titulo == other.titulo
|
95
|
+
return @porcentaje_diario <=> other.porcentaje_diario unless @porcentaje_diario == other.porcentaje_diario
|
96
|
+
return @platos <=> other.platos unless @platos & other.platos == @platos
|
97
|
+
return @titulo <=> other.titulo unless @titulo == other.titulo
|
98
|
+
return @porcentaje_proteinas <=> other.porcentaje_proteinas unless @porcentaje_proteinas == other.porcentaje_proteinas
|
99
|
+
return @porcentaje_grasas <=> other.porcentaje_grasas unless @porcentaje_grasas == other.porcentaje_grasas
|
100
|
+
return @porcentaje_hidratos <=> other.porcentaje_hidratos
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Menú dietético con un tipo de alimentos específicos compuesto por varios platos
|
4
|
+
#
|
5
|
+
# @author Ruymán Rodríguez Martín <alu0100845235@ull.edu.es>
|
6
|
+
#
|
7
|
+
# @attr_reader [String] tipo_alimentos Tipos de alimentos que contiene
|
8
|
+
class MenuPorAlimentos < Menu
|
9
|
+
attr_reader :tipo_alimentos
|
10
|
+
|
11
|
+
# Constructor
|
12
|
+
# @param titulo [String] Título del menú
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
# Asigna el tipo de alimentos
|
18
|
+
# @param valor [String] descripción tipo de alimentos
|
19
|
+
def tipo(valor)
|
20
|
+
raise ArgumentError.new("tipo_alimentos no es un String") if !valor.instance_of?(String)
|
21
|
+
@tipo_alimentos = valor
|
22
|
+
end
|
23
|
+
|
24
|
+
# Devuelve una cadena de texto que representa al menú
|
25
|
+
def to_s
|
26
|
+
s = "#{@titulo.upcase} (#{@porcentaje_diario}%)\n"
|
27
|
+
s << "Tipo de alimentos: #{@tipo_alimentos}\n"
|
28
|
+
@platos.each do |plato|
|
29
|
+
s << "- #{plato.to_s}"
|
30
|
+
end
|
31
|
+
s << "V.C.T | %\t#{@vct.round(1)} kcal | #{@porcentaje_proteinas}% - #{@porcentaje_grasas}% - #{@porcentaje_hidratos}%\n"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# Menú dietético para unas edades específicas compuesto por varios platos
|
4
|
+
#
|
5
|
+
# @author Ruymán Rodríguez Martín <alu0100845235@ull.edu.es>
|
6
|
+
#
|
7
|
+
# @attr_reader [String] edad Edad para la que es recomendable
|
8
|
+
class MenuPorEdad < Menu
|
9
|
+
attr_reader :edad
|
10
|
+
|
11
|
+
# Constructor
|
12
|
+
def initialize
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
# Asigna la edad recomendada
|
17
|
+
# @param valor [String] Descripción de las edades recomendadas
|
18
|
+
def edades(valor)
|
19
|
+
raise ArgumentError.new("Edad no es un String") if !valor.instance_of?(String)
|
20
|
+
@edad = valor
|
21
|
+
end
|
22
|
+
|
23
|
+
# Devuelve una cadena de texto que representa al menú
|
24
|
+
def to_s
|
25
|
+
s = "#{@titulo.upcase} (#{@porcentaje_diario}%)\n"
|
26
|
+
s << "Edad recomendada: #{@edad}\n"
|
27
|
+
@platos.each do |plato|
|
28
|
+
s << "- #{plato.to_s}"
|
29
|
+
end
|
30
|
+
s << "V.C.T | %\t#{@vct.round(1)} kcal | #{@porcentaje_proteinas}% - #{@porcentaje_grasas}% - #{@porcentaje_hidratos}%\n"
|
31
|
+
end
|
32
|
+
end
|
data/lib/Dieta/nodo.rb
ADDED
data/lib/Dieta/plato.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# Plato de comida
|
5
|
+
#
|
6
|
+
# @author Ruymán Rodríguez Martín <alu0100845235@ull.edu.es>
|
7
|
+
#
|
8
|
+
# @attr_reader [String] descripcion Descripción del plato
|
9
|
+
# @attr_reader [String] porcion_recomendada Porción recomendada
|
10
|
+
# @attr_reader [String] cantidad_ingesta Cantidad a ingerir
|
11
|
+
class Plato
|
12
|
+
include Comparable
|
13
|
+
attr_reader :descripcion, :porcion_recomendada, :cantidad_ingesta
|
14
|
+
|
15
|
+
# Constructor
|
16
|
+
# @param descripcion [String] Descripción del plato
|
17
|
+
# @param porcion_recomendada [String] Porción recomendada
|
18
|
+
# @param cantidad_ingesta [String] Cantidad a ingerir
|
19
|
+
def initialize (&block)
|
20
|
+
# Inicializar variables
|
21
|
+
if block_given?
|
22
|
+
# Recibimos un bloque
|
23
|
+
if block.arity == 1
|
24
|
+
yield self
|
25
|
+
else
|
26
|
+
instance_eval &block
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Asigna la descripcion
|
32
|
+
# @param valor [String] Descripcion
|
33
|
+
def description(valor)
|
34
|
+
raise ArgumentError.new("Porcion Recomendada no es un String") if !valor.instance_of?(String)
|
35
|
+
@descripcion = valor
|
36
|
+
end
|
37
|
+
|
38
|
+
# Asigna la porción recomendada
|
39
|
+
# @param cantidad [String] Porción recomendada
|
40
|
+
def porcion(cantidad)
|
41
|
+
raise ArgumentError.new("Porcion Recomendada no es un String") if !cantidad.instance_of?(String)
|
42
|
+
@porcion_recomendada = cantidad
|
43
|
+
end
|
44
|
+
|
45
|
+
# Asigna la cantidad de ingesta
|
46
|
+
# @param valor [String] cantidad de ingesta
|
47
|
+
def cantidad(valor)
|
48
|
+
raise ArgumentError.new("Cantidad Ingesta no es un String") if !valor.instance_of?(String)
|
49
|
+
@cantidad_ingesta = valor
|
50
|
+
end
|
51
|
+
|
52
|
+
# Devuelve una cadena de texto que representa al plato
|
53
|
+
def to_s
|
54
|
+
s = "#{@descripcion}, "
|
55
|
+
if @porcion_recomendada != ""
|
56
|
+
s << "#{@porcion_recomendada}, "
|
57
|
+
end
|
58
|
+
s << "#{@cantidad_ingesta}\n"
|
59
|
+
end
|
60
|
+
|
61
|
+
# Función de comparación para Mixin Comparable
|
62
|
+
def <=> (other)
|
63
|
+
# devolvemos nil si no son del tipo Plato
|
64
|
+
return nil unless other.is_a? Plato
|
65
|
+
# realizamos las comparaciones necesarias
|
66
|
+
return @descripcion <=> other.descripcion unless @descripcion == other.descripcion
|
67
|
+
return @porcion_recomendada <=> other.porcion_recomendada unless @porcion_recomendada == other.porcion_recomendada
|
68
|
+
return @cantidad_ingesta <=> other.cantidad_ingesta
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Dieta-alu0100845235
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ruyman Rodriguez Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-16 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: Permite las definiciones de menús dietéticos diarios y semanales
|
98
|
+
email:
|
99
|
+
- alu0100845235@ull.edu.es
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Dieta.gemspec
|
108
|
+
- Gemfile
|
109
|
+
- Guardfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- lib/Dieta.rb
|
116
|
+
- lib/Dieta/lista.rb
|
117
|
+
- lib/Dieta/menu.rb
|
118
|
+
- lib/Dieta/menu_alimentos.rb
|
119
|
+
- lib/Dieta/menu_edad.rb
|
120
|
+
- lib/Dieta/nodo.rb
|
121
|
+
- lib/Dieta/plato.rb
|
122
|
+
- lib/Dieta/version.rb
|
123
|
+
homepage: https://github.com/ULL-ESIT-LPP-1617/menu-dietetico-alu0100845235
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.6
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: ''
|
147
|
+
test_files: []
|