alimentarse 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/.coveralls.yml +1 -0
- data/.gitignore +12 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +8 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/alimentos.gemspec +41 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/alimentos.rb +92 -0
- data/lib/alimentos/lista.rb +129 -0
- data/lib/alimentos/version.rb +5 -0
- data/lib/alimentosdsl.rb +181 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 323084cf246b14e845a9655d0f45f562a4131437
|
4
|
+
data.tar.gz: d5ab6bd54633b7541df0a3917e125ec73ddf982c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 322528ecd599457fb375bb0d51b3492058e03534a4a9352ecd616829cba30d23aee629decad4fafcd308cf10766ab53805f57d2213d67d74941e7719495f3de2
|
7
|
+
data.tar.gz: b61455bbd18afefec9b9c50facf0ff4a94aa53595f91500a1978d54a0ae6ca9f5fc77b45d6e91fd172a39bd74b9e9deb362c2623696853d88f44bde3807c598e
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-cl
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 cristian_gonzalez_alonso@hotmail.com. 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
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) 2017 criscrack
|
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,43 @@
|
|
1
|
+
# Alimentos
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/alimentos`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'alimentos'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install alimentos
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/alimentos. 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.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Alimentos project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/alimentos/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/alimentos.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 "alimentos/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "alimentarse"
|
8
|
+
spec.version = Alimentos::VERSION
|
9
|
+
spec.authors = ["criscrack"]
|
10
|
+
spec.email = ["cristian_gonzalez_alonso@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{"https://github.com/ULL-ESIT-LPP-1718/tdd-alu0100887778"}
|
13
|
+
spec.description = %q{"Clase para mostrar las proteinas, glucidos, lipidos y valor calorico de alimentos"}
|
14
|
+
spec.homepage = 'http://rubygems.org/gems/alimentense'
|
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"] = "TODO: Set to 'http://rubygems.com'"
|
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 "coveralls"
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
37
|
+
spec.add_development_dependency "guard"
|
38
|
+
spec.add_development_dependency "guard-rspec"
|
39
|
+
spec.add_development_dependency "guard-bundler"
|
40
|
+
|
41
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "alimentos"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/alimentos.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "alimentos/version.rb"
|
2
|
+
|
3
|
+
#Modulo alimentos
|
4
|
+
module Alimentos
|
5
|
+
|
6
|
+
#Clase alimentos
|
7
|
+
class Alimentos
|
8
|
+
|
9
|
+
#Añadimos atributos de lectura
|
10
|
+
attr_reader :alimentos, :proteinas, :glucidos, :lipidos
|
11
|
+
attr_accessor :data
|
12
|
+
|
13
|
+
|
14
|
+
##Incluimos el comparablddde
|
15
|
+
include Comparable
|
16
|
+
|
17
|
+
#Inicializamos las variables
|
18
|
+
def initialize(alimento,proteinas,glucidos,lipidos)
|
19
|
+
|
20
|
+
@alimento = alimento
|
21
|
+
@proteinas = proteinas
|
22
|
+
@glucidos = glucidos
|
23
|
+
@lipidos = lipidos
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
#Método para obtener el nombre del alimento
|
28
|
+
def get_ali(i)
|
29
|
+
@alimento[i]
|
30
|
+
end
|
31
|
+
|
32
|
+
#Método para obtener las proteinas del alimento
|
33
|
+
def get_proteinas(i)
|
34
|
+
@proteinas[i]
|
35
|
+
end
|
36
|
+
|
37
|
+
#Método para obtener los glucidos del alimento
|
38
|
+
def get_glucidos(i)
|
39
|
+
@glucidos[i]
|
40
|
+
end
|
41
|
+
|
42
|
+
#Método para obtener los lipidos del alimento
|
43
|
+
def get_lipidos(i)
|
44
|
+
@lipidos[i]
|
45
|
+
end
|
46
|
+
|
47
|
+
#Método para obtener el valor energético del alimento
|
48
|
+
def get_calorias(i)
|
49
|
+
@calorias = [0.0]
|
50
|
+
@calorias [i] = ((@proteinas[i]*4)+(@glucidos[i]*4)+(@lipidos[i]*9))
|
51
|
+
end
|
52
|
+
|
53
|
+
#Método para obtener el formateado del alimento
|
54
|
+
def get_formateado(i)
|
55
|
+
get_calorias(i)
|
56
|
+
"#{@alimento[i]}" " = " "#{@proteinas[i]}" " gr de proteinas + " "#{@glucidos[i]}" " gr de glucidos + " "#{@lipidos[i]}" " gr de lipidos | " "#{@calorias[i]}" " Kcal en total"
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
##Metodo menor,mayor o igual del enumerable
|
62
|
+
def <=> (another)
|
63
|
+
@proteinas <=> another.proteinas
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
##Metodo para calcular AIBC
|
68
|
+
def aibc(index)
|
69
|
+
auxiliar = []
|
70
|
+
data[index][1..data[index].length - 1].zip(data[index][0..data[index].length-2]) do |x,y|
|
71
|
+
if x < data[index][0]
|
72
|
+
auxiliar << 0.0
|
73
|
+
else
|
74
|
+
auxiliar << (((x - data[index][0]) + (y - data[index][0]))/2) * 5
|
75
|
+
end
|
76
|
+
end
|
77
|
+
auxiliar.reduce(:+)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
##Clase Lacteos heredada de alimentos
|
84
|
+
class Lacteos < Alimentos::Alimentos
|
85
|
+
|
86
|
+
##Inicializacio de variables de la clase
|
87
|
+
def initialize(alimento, proteinas, glucidos, lipidos, subali)
|
88
|
+
super(alimento,proteinas,glucidos,lipidos)
|
89
|
+
@subali = subali
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
|
2
|
+
##Creamos la estructura de un nodo nuevo, con su valor, su nodo siguiente y su nodo rpevio
|
3
|
+
Nodo = Struct.new(:valor, :siguiente, :prev)
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
##Definicion de la Clase Lista
|
8
|
+
class Lista
|
9
|
+
|
10
|
+
##Incluimos el Enumerable
|
11
|
+
include Enumerable
|
12
|
+
|
13
|
+
##Añadimos atributo de lectura
|
14
|
+
attr_reader :cabecera, :cola, :size
|
15
|
+
|
16
|
+
|
17
|
+
##Inicializamos la cabecera y la cola de la lista a nulo
|
18
|
+
def initialize
|
19
|
+
@cabecera = nil
|
20
|
+
@cola= nil
|
21
|
+
@size = 0
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
##Metodo push de a lista que introduce los valores dentro de la misma
|
26
|
+
def push (valores)
|
27
|
+
|
28
|
+
if(valores.instance_of? Array)
|
29
|
+
if(@cola == nil)
|
30
|
+
|
31
|
+
@cola = Nodo.new(valores[0],nil,nil)
|
32
|
+
@cabecera = @cola
|
33
|
+
valores.shift()
|
34
|
+
@size = @size + 1
|
35
|
+
end
|
36
|
+
|
37
|
+
valores.each do |valor|
|
38
|
+
aux= @cabecera
|
39
|
+
@cabecera = Nodo.new(valor,nil,aux)
|
40
|
+
aux.siguiente= @cabecera
|
41
|
+
@size = @size + 1
|
42
|
+
end
|
43
|
+
else
|
44
|
+
|
45
|
+
if(@cola==nil)
|
46
|
+
@cola = Nodo.new(valores,nil,nil)
|
47
|
+
@cabecera = @cola
|
48
|
+
@size = @size + 1
|
49
|
+
else
|
50
|
+
aux= @cabecera
|
51
|
+
@cabecera = Nodo.new(valores,nil,aux)
|
52
|
+
aux.siguiente= @cabecera
|
53
|
+
@size = @size + 1
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
##Funcion pop que devuelve el valor de la cabecera y la elimina de la lista
|
61
|
+
def pop
|
62
|
+
if(@cabecera!=nil)
|
63
|
+
node = @cabecera
|
64
|
+
@cabecera = @cabecera.prev
|
65
|
+
if(@cabecera!=nil)
|
66
|
+
@cabecera.siguiente = nil
|
67
|
+
node.prev= nil
|
68
|
+
else @cola = nil
|
69
|
+
end
|
70
|
+
return node.valor
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
##metodo each
|
75
|
+
def each
|
76
|
+
nodo = @cola
|
77
|
+
while(nodo != nil)
|
78
|
+
yield nodo.valor
|
79
|
+
nodo = nodo.siguiente
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def convert lista
|
84
|
+
lista.map { |x| x}
|
85
|
+
end
|
86
|
+
|
87
|
+
#Método para ordenar un array creado a partir de una lista.
|
88
|
+
def ordenarFor lista
|
89
|
+
auxList = lista.convert lista
|
90
|
+
for i in 0..(auxList.length) do
|
91
|
+
for j in 0..(auxList.length-2) do
|
92
|
+
if(auxList[j].to_f > auxList[j+1].to_f)
|
93
|
+
temporal = auxList[j]
|
94
|
+
auxList[j] = auxList[j+1]
|
95
|
+
auxList[j+1] = temporal
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
auxList
|
100
|
+
end
|
101
|
+
|
102
|
+
#Método para ordenar un array creado a partir de una lista.
|
103
|
+
def ordenarEach lista
|
104
|
+
auxList = lista.convert lista
|
105
|
+
indice = 0
|
106
|
+
auxList.each do |x|
|
107
|
+
auxList.each do |y|
|
108
|
+
if (indice < auxList.length-1)
|
109
|
+
if (auxList[indice].to_f > auxList[indice+1].to_f)
|
110
|
+
temporal = auxList[indice]
|
111
|
+
auxList[indice] = auxList[indice+1]
|
112
|
+
auxList[indice+1] = temporal
|
113
|
+
end
|
114
|
+
end
|
115
|
+
indice = indice+1
|
116
|
+
end
|
117
|
+
indice = 0
|
118
|
+
end
|
119
|
+
auxList
|
120
|
+
end
|
121
|
+
|
122
|
+
#Método para ordenar un array creado a partir de una lista usando el método sort
|
123
|
+
def ordenarSort lista
|
124
|
+
auxList = lista.convert lista
|
125
|
+
auxList.sort
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
data/lib/alimentosdsl.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
class DietaDSL
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "./lib/alimentos.rb"
|
5
|
+
require "./lib/alimentosdsl.rb"
|
6
|
+
require "./lib/alimentos/lista.rb"
|
7
|
+
|
8
|
+
|
9
|
+
##Incluimos el comparable
|
10
|
+
include Comparable
|
11
|
+
|
12
|
+
##Añadimos atributo de lectura
|
13
|
+
attr_reader :nombre, :vct, :vegetal, :fruta, :cereal,:proteina, :aceite , :platos
|
14
|
+
|
15
|
+
|
16
|
+
#Incializamos las variables descripcion, ingredientes e informacion de la dieta
|
17
|
+
|
18
|
+
def initialize(nombre, &block)
|
19
|
+
|
20
|
+
@nombre = nombre
|
21
|
+
@titulo = ""
|
22
|
+
@vegetal = []
|
23
|
+
@fruta = []
|
24
|
+
@cereal = []
|
25
|
+
@proteina = []
|
26
|
+
@aceite = []
|
27
|
+
@platos = []
|
28
|
+
@porcentajes = []
|
29
|
+
@vct= 0
|
30
|
+
|
31
|
+
if block_given?
|
32
|
+
if block.arity == 1
|
33
|
+
yield self
|
34
|
+
else
|
35
|
+
instance_eval(&block)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
def titulo_ (nombre_ali)
|
43
|
+
nombre_ali = @nombre
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def vegetal_(nombre_ingred, opciones={})
|
48
|
+
|
49
|
+
nombre = nombre_ingred
|
50
|
+
porcion=""
|
51
|
+
glucidos= ""
|
52
|
+
proteinas= ""
|
53
|
+
lipidos= ""
|
54
|
+
porcion= opciones[:porcion] if opciones[:porcion]
|
55
|
+
@vct = opciones[:vct] if opciones[:vct]
|
56
|
+
proteinas = opciones[:proteinas] if opciones[:proteinas]
|
57
|
+
glucidos = opciones[:glucidos] if opciones[:glucidos]
|
58
|
+
lipidos = opciones[:lipidos] if opciones[:lipidos]
|
59
|
+
@vegetal.push([nombre,porcion,proteinas,glucidos,lipidos,vct])
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
def cereal_(nombre_ingred, opciones={})
|
64
|
+
|
65
|
+
nombre = nombre_ingred
|
66
|
+
porcion=""
|
67
|
+
glucidos= ""
|
68
|
+
proteinas= ""
|
69
|
+
lipidos= ""
|
70
|
+
porcion= opciones[:porcion] if opciones[:porcion]
|
71
|
+
@vct = opciones[:vct] if opciones[:vct]
|
72
|
+
proteinas = opciones[:proteinas] if opciones[:proteinas]
|
73
|
+
glucidos = opciones[:glucidos] if opciones[:glucidos]
|
74
|
+
lipidos = opciones[:lipidos] if opciones[:lipidos]
|
75
|
+
@cereal.push([nombre,porcion,proteinas,glucidos,lipidos,vct])
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def fruta_(nombre_ingred, opciones={})
|
80
|
+
|
81
|
+
nombre = nombre_ingred
|
82
|
+
gramos=""
|
83
|
+
glucidos= ""
|
84
|
+
proteinas= ""
|
85
|
+
lipidos= ""
|
86
|
+
gramos= opciones[:gramos] if opciones[:gramos]
|
87
|
+
@vct = opciones[:vct] if opciones[:vct]
|
88
|
+
proteinas = opciones[:proteinas] if opciones[:proteinas]
|
89
|
+
glucidos = opciones[:glucidos] if opciones[:glucidos]
|
90
|
+
lipidos = opciones[:lipidos] if opciones[:lipidos]
|
91
|
+
@fruta.push([nombre,gramos,proteinas,glucidos,lipidos,vct])
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
def proteina_(nombre_ingred, opciones={})
|
96
|
+
nombre = nombre_ingred
|
97
|
+
porcion=""
|
98
|
+
glucidos= ""
|
99
|
+
proteinas= ""
|
100
|
+
lipidos= ""
|
101
|
+
porcion= opciones[:porcion] if opciones[:porcion]
|
102
|
+
@vct = opciones[:vct] if opciones[:vct]
|
103
|
+
proteinas = opciones[:proteinas] if opciones[:proteinas]
|
104
|
+
glucidos = opciones[:glucidos] if opciones[:glucidos]
|
105
|
+
lipidos = opciones[:lipidos] if opciones[:lipidos]
|
106
|
+
@proteina.push([nombre,porcion,proteinas,glucidos,lipidos,vct])
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
def aceite_(nombre_ingred, opciones={})
|
111
|
+
nombre = nombre_ingred
|
112
|
+
porcion=""
|
113
|
+
glucidos= ""
|
114
|
+
proteinas= ""
|
115
|
+
lipidos= ""
|
116
|
+
porcion= opciones[:porcion] if opciones[:porcion]
|
117
|
+
@vct = opciones[:vct] if opciones[:vct]
|
118
|
+
proteinas = opciones[:proteinas] if opciones[:proteinas]
|
119
|
+
glucidos = opciones[:glucidos] if opciones[:glucidos]
|
120
|
+
lipidos = opciones[:lipidos] if opciones[:lipidos]
|
121
|
+
@aceite.push([nombre,porcion,proteinas,glucidos,lipidos,vct])
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_s
|
125
|
+
salida = []
|
126
|
+
salida = @nombre + "\n"
|
127
|
+
salida += "=============================================================\n"
|
128
|
+
salida += "Composición nutricional: \n"
|
129
|
+
salida += "Alimento\t\tCantidad\t\t\tProteinas\t\tGlucidos\t\tLípidos\t\tValor energético\n"
|
130
|
+
|
131
|
+
for i in (0..5) do
|
132
|
+
salida += @vegetal[0][i].to_s + "\t\t\t"
|
133
|
+
end
|
134
|
+
|
135
|
+
salida += "\n"
|
136
|
+
|
137
|
+
for i in (0..5) do
|
138
|
+
salida += @fruta[0][i].to_s + "\t\t"
|
139
|
+
end
|
140
|
+
|
141
|
+
salida += "\n"
|
142
|
+
|
143
|
+
salida += @cereal[0][0] + "\t\t\t"
|
144
|
+
salida += @cereal[0][1] + "\t\t\t\t"
|
145
|
+
for i in (2..5) do
|
146
|
+
salida += @cereal[0][i].to_s + "\t\t\t"
|
147
|
+
end
|
148
|
+
|
149
|
+
salida += "\n"
|
150
|
+
|
151
|
+
for i in (0..5) do
|
152
|
+
salida += @aceite[0][i].to_s + "\t\t\t"
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
salida += "\n"
|
157
|
+
|
158
|
+
for i in (0..1) do
|
159
|
+
for j in (0..5) do
|
160
|
+
salida += @proteina[i][j].to_s + "\t\t"
|
161
|
+
end
|
162
|
+
salida += "\n"
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
salida += "\n"
|
167
|
+
|
168
|
+
salida += "Valor energetico total: \t\t\t\t\t\t\t\t\t\t"
|
169
|
+
@valor_energetico = ( @vegetal[0][5]+ @fruta[0][5]+ @cereal[0][5]+ @proteina[0][5]+ @proteina[1][5] + aceite[0][5] ).round(3)
|
170
|
+
salida += "#{@valor_energetico}"
|
171
|
+
|
172
|
+
salida += "\n"
|
173
|
+
salida += "\n"
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
salida
|
178
|
+
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alimentarse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- criscrack
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coveralls
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
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-rspec
|
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: guard-bundler
|
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: '"Clase para mostrar las proteinas, glucidos, lipidos y valor calorico
|
112
|
+
de alimentos"'
|
113
|
+
email:
|
114
|
+
- cristian_gonzalez_alonso@hotmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".coveralls.yml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".travis.yml"
|
122
|
+
- CODE_OF_CONDUCT.md
|
123
|
+
- Gemfile
|
124
|
+
- Guardfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- alimentos.gemspec
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- lib/alimentos.rb
|
132
|
+
- lib/alimentos/lista.rb
|
133
|
+
- lib/alimentos/version.rb
|
134
|
+
- lib/alimentosdsl.rb
|
135
|
+
homepage: http://rubygems.org/gems/alimentense
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.6.11
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: '"https://github.com/ULL-ESIT-LPP-1718/tdd-alu0100887778"'
|
159
|
+
test_files: []
|