nutrientes12345 0.2.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.
@@ -0,0 +1,37 @@
1
+ require "nutrientes/version"
2
+ require "nutrientes"
3
+
4
+ # this is a subclass of the Alimento-class
5
+ class HuevosLacteosHelados < Alimento
6
+
7
+ end
8
+
9
+ # this is a subclass of the Alimento-class
10
+ class CarnesDerivados < Alimento
11
+
12
+ end
13
+
14
+ # this is a subclass of the Alimento-class
15
+ class PescadosMariscos < Alimento
16
+
17
+ end
18
+
19
+ # this is a subclass of the Alimento-class
20
+ class AlimentosGrasos < Alimento
21
+
22
+ end
23
+
24
+ # this is a subclass of the Alimento-class
25
+ class AlimentosCarbohidratos < Alimento
26
+
27
+ end
28
+
29
+ # this is a subclass of the Alimento-class
30
+ class VerdurasHortalizas < Alimento
31
+
32
+ end
33
+
34
+ # this is a subclass of the Alimento-class
35
+ class Frutas < Alimento
36
+
37
+ end
@@ -0,0 +1,99 @@
1
+ require 'nutrientes/version'
2
+
3
+ # This class is used to represent double-linked lists
4
+ # It includes the mixin Enumerable
5
+ class List
6
+
7
+ include Enumerable
8
+ # This structure is used to represent Nodes in the List,
9
+ # which have a value, a next node and a previous node
10
+ Node = Struct.new("Node", :value, :next, :prev)
11
+
12
+ # initializes the vales of the list's head and tail to nil
13
+ def initialize
14
+
15
+ @head = nil
16
+ @tail = nil
17
+
18
+ end
19
+
20
+ # returns true if the list is empty and false else
21
+ def isEmpty?
22
+ if @head == nil then
23
+ true
24
+ else
25
+ false
26
+ end
27
+ end
28
+
29
+ # adds a value to the end of the list, behind the former last element
30
+ # if it's the first element, this becomes the new head and tail
31
+ def add (value)
32
+
33
+ if @tail == nil then
34
+ @head = Node.new(value, nil, nil)
35
+ @tail = @head
36
+ else
37
+ temp = Node.new(value, nil, @tail)
38
+ @tail.next = temp
39
+ @tail = temp
40
+ end
41
+
42
+ end
43
+
44
+ # adds all elements in the given Array to our list. This works by
45
+ # calling the add(value)-method for each element in the array
46
+ def addAll (array)
47
+
48
+ array.each { |value| add(value) }
49
+
50
+ end
51
+
52
+ # returns the head-node
53
+ def getNode
54
+
55
+ @head
56
+
57
+ end
58
+
59
+ # returns the value of the head
60
+ def head
61
+ @head.value
62
+ end
63
+
64
+ # returns the value of the tail
65
+ def tail
66
+ @tail.value
67
+ end
68
+
69
+ # returns an array with all the values of this list
70
+ def to_a
71
+ tempArray = []
72
+ tempNode = @head
73
+ while tempNode != nil do
74
+ tempArray.push(tempNode.value)
75
+ tempNode = tempNode.next
76
+ end
77
+ tempArray
78
+ end
79
+
80
+ # returns an array with all the values of this list,
81
+ # but in a reverse order
82
+ def to_a_reverse
83
+ tempArray = []
84
+ tempNode = @tail
85
+ while tempNode != nil do
86
+ tempArray.push(tempNode.value)
87
+ tempNode = tempNode.prev
88
+ end
89
+ tempArray
90
+ end
91
+
92
+ # this method is included because we implement the method
93
+ # Enumerable. Yields every element in the list, one after
94
+ # another, by calling the to_a-method.
95
+ def each
96
+ self.to_a.each { |i| yield i }
97
+ end
98
+
99
+ end
@@ -0,0 +1,59 @@
1
+ require "nutrientes/version"
2
+
3
+ # This class allows to represent a food. It includes the foods
4
+ # Macronutrients and a way to calculate the energetic value.
5
+ # The mixin Comparable is included.
6
+ class Alimento
7
+
8
+ include Comparable
9
+ attr_reader :nombre, :proteinas, :glucidos, :grasas
10
+
11
+ # Name and percentage of proteins, carbohydrates and fats are assigned
12
+ def initialize (nombre, proteinas, glucidos, grasas)
13
+ @nombre = nombre
14
+ @proteinas = proteinas
15
+ @glucidos = glucidos
16
+ @grasas = grasas
17
+ @concentracionThis = []
18
+ @concentracionGlucosa = []
19
+
20
+ end
21
+
22
+ # returns this food in a nicely formatted way
23
+ def to_s
24
+ "#{@nombre}:\nProteínas:\t\t #{@proteinas} gramos\nGlúcidos:\t\t #{@glucidos} gramos\nLípidos:\t\t #{@grasas} gramos\n\t\t\t por 100 gramos\nValor energetico:\t #{valorEnergetico().round(1)}"
25
+ end
26
+
27
+ # calculates the energetic value of a food, generally of 100 grams
28
+ # of this food. This can be changed by the user, depending on her needs
29
+ def valorEnergetico (gramos = 100)
30
+ ((@proteinas * 4 + @glucidos * 4 + @grasas * 9) / 100) * gramos
31
+ end
32
+
33
+ # This method is defined because we included the mixin Comparable
34
+ # We take the energetic Value as our means to compare two foods
35
+ def <=> (anOther)
36
+ if anOther.is_a?(Alimento) == false
37
+ nil
38
+ else
39
+ self.valorEnergetico <=> anOther.valorEnergetico
40
+ end
41
+ end
42
+
43
+ # Adds a pair of measurements to the data of this food
44
+ def addMeasurement (alimento, glucosa)
45
+ @concentracionThis << alimento
46
+ @concentracionGlucosa << glucosa
47
+ end
48
+
49
+ # calculates the glucemic index of this food based on its values that were
50
+ # added in addMeasurement
51
+ def indiceGlucemico
52
+ # AIBC
53
+ aibc = lambda {|list| list.drop(1).zip(list.first(list.count - 1)).map {|i| i[0] < list.first ? 0 : (((i[0] - list.first) + (i[1] - list.first))/2) * 5}.reduce(:+)}
54
+ # IG ind
55
+ igIndAll = @concentracionThis.zip(@concentracionGlucosa).map{|dataPair| [aibc.call(dataPair[0]), aibc.call(dataPair[1])]}.map{|aibcPair| (aibcPair[0] / aibcPair[1]) * 100}
56
+ # IG
57
+ igIndAll.reduce(:+)/igIndAll.count
58
+ end
59
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ # This module was created to represent different kids of
3
+ # foods. There has also been added a double-linked list.
4
+ # All documents are written in the programming language Ruby
5
+ # The programming examples of the class "Lenguajes y Paradigmas
6
+ # de Programación" have been developed
7
+ #
8
+ # Author:: Malte Bossert
9
+
10
+ module Nutrientes
11
+ # The actual version of the Ruby gem
12
+ VERSION = "0.2.0"
13
+ end
@@ -0,0 +1,141 @@
1
+ require 'nutrientes/version'
2
+ require 'nutrientes'
3
+ require 'jerarquia'
4
+
5
+ # this class represents plates that follow the concept of
6
+ # harvard health experts
7
+ class Plato
8
+
9
+ attr_accessor :name
10
+
11
+ # all known foods that can be inside a plate
12
+ @@tabla = [
13
+ HuevosLacteosHelados.new("Huevo", 14.1, 0.0, 19.5),
14
+ HuevosLacteosHelados.new("Leche", 3.3, 4.8, 3.2),
15
+ HuevosLacteosHelados.new("Yogurt", 3.8, 4.9, 3.8),
16
+ CarnesDerivados.new("Cerdo", 21.5, 0.0, 6.3),
17
+ CarnesDerivados.new("Ternera", 21.1, 0.0, 3.1),
18
+ CarnesDerivados.new("Pollo", 20.6, 0.0, 5.6),
19
+ PescadosMariscos.new("Bacalao", 17.7, 0.0, 0.4),
20
+ PescadosMariscos.new("Atún", 21.5, 0.0, 15.5),
21
+ PescadosMariscos.new("Salmón", 19.9, 0.0, 13.6),
22
+ AlimentosGrasos.new("Aceite de oliva", 0.0, 0.2, 99.6),
23
+ AlimentosGrasos.new("Mantequilla", 0.7, 0.0, 83.2),
24
+ AlimentosGrasos.new("Chocolate", 5.3, 47.0, 30.0),
25
+ AlimentosCarbohidratos.new("Azúcar", 0.0, 99.8, 0.0),
26
+ AlimentosCarbohidratos.new("Arroz", 6.8, 77.7, 0.6),
27
+ AlimentosCarbohidratos.new("Lentejas", 23.5, 52.0, 1.4),
28
+ AlimentosCarbohidratos.new("Papas", 2.0, 15.4, 0.1),
29
+ VerdurasHortalizas.new("Tomate", 1.0, 3.5, 0.2),
30
+ VerdurasHortalizas.new("Cebolla", 1.3, 5.8, 0.3),
31
+ VerdurasHortalizas.new("Calabaza", 1.1, 4.8, 0.1),
32
+ Frutas.new("Manzana", 0.3, 12.4, 0.4),
33
+ Frutas.new("Plátano", 1.2, 21.4, 0.2),
34
+ Frutas.new("Pera", 0.5, 12.7, 0.3)
35
+ ]
36
+ @@unityConverter = {
37
+ "piezas pequeñas" => 30,
38
+ "pieza pequeña" => 30,
39
+ "taza" => 200,
40
+ "tazas" => 200,
41
+ "cucharón" => 70,
42
+ "cucharónes" => 70,
43
+ "pieza" => 50,
44
+ "piezas" => 50,
45
+ "cucharada" => 10,
46
+ "cucharadas" => 10
47
+ }
48
+ def initialize(name, &bloque)
49
+ @name = name.strip
50
+ @ingredients = {
51
+ "vegetales" => [],
52
+ "frutas" => [],
53
+ "granos" => [],
54
+ "proteina" => [],
55
+ "aceite" => []
56
+ }
57
+ @valorEnergetico = 0
58
+
59
+ if block_given?
60
+ if bloque.arity == 1
61
+ yield self
62
+ else
63
+ instance_eval(&bloque)
64
+ end
65
+ end
66
+ end
67
+
68
+ def vegetal(name, amount)
69
+ @@tabla.each{ |value| if value.nombre == name
70
+ @ingredients["vegetales"] << [value, translateAmount(amount)]
71
+ @valorEnergetico += value.valorEnergetico(translateAmount(amount))
72
+ end
73
+ }
74
+ end
75
+ def fruta(name, amount)
76
+ @@tabla.each{ |value| if value.nombre == name
77
+ @ingredients["frutas"] << [value, translateAmount(amount)]
78
+ @valorEnergetico += value.valorEnergetico(translateAmount(amount))
79
+ end
80
+ }
81
+ end
82
+ def cereal(name, amount)
83
+ @@tabla.each{ |value| if value.nombre == name
84
+ @ingredients["granos"] << [value, translateAmount(amount)]
85
+ @valorEnergetico += value.valorEnergetico(translateAmount(amount))
86
+ end
87
+ }
88
+ end
89
+ def proteina(name, amount)
90
+ @@tabla.each{ |value| if value.nombre == name
91
+ @ingredients["proteina"] << [value, translateAmount(amount)]
92
+ @valorEnergetico += value.valorEnergetico(translateAmount(amount))
93
+ end
94
+ }
95
+ end
96
+ def aceite(name, amount)
97
+ @@tabla.each{ |value| if value.nombre == name
98
+ @ingredients["aceite"] << [value, translateAmount(amount)]
99
+ @valorEnergetico += value.valorEnergetico(translateAmount(amount))
100
+ end
101
+ }
102
+ end
103
+
104
+ def translateAmount(amount)
105
+ if amount[:gramos] != nil
106
+ amount[:gramos]
107
+ elsif amount[:porcion] != nil
108
+ text = amount[:porcion].partition(" ")
109
+ number = text[0].strip.to_f
110
+ amount = @@unityConverter[text[2].strip.to_s]
111
+ number * amount
112
+ else
113
+ nil
114
+ end
115
+ end
116
+
117
+ def to_s
118
+ text = @name
119
+ text << "\n"
120
+ temp = "=" * (@name.length-1)
121
+ text << temp
122
+ text << "\nComposición nutricional\n"
123
+ text << " glúcidos proteínas lípidos valor energético\n" #17 spaces
124
+ @ingredients.each{|temp| temp[1].each {|alimento| text << format(alimento)}}
125
+ text << adjust("Valor energético total", 53)
126
+ text << @valorEnergetico.round(1).to_s
127
+
128
+
129
+ text
130
+ end
131
+
132
+ def format(alimento)
133
+ value = alimento[0]
134
+ str = adjust(value.nombre, 17) + "#{adjust(value.glucidos, 12)}#{adjust(value.proteinas, 12)}#{adjust(value.grasas, 12)}#{adjust(value.valorEnergetico(alimento[1]).round(1), 6)}(#{alimento[1].round} gramos)\n"
135
+ end
136
+
137
+ def adjust(str, length)
138
+ str = str.to_s
139
+ str + " " * (length - str.length)
140
+ end
141
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nutrientes/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nutrientes12345"
8
+ spec.version = Nutrientes::VERSION
9
+ spec.authors = ["Malte Bossert"]
10
+ spec.email = ["alu0101182773@ull.edu.es"]
11
+
12
+ spec.summary = %q{Gem to represent foods and their nutrients.}
13
+ spec.description = %q{This gem includes a class that was built using test-driven development with rspec. It can be initialised with a food and its values (in gramms) of macronutrients, say Carbohydrates, Fats and Proteins}
14
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1718/tdd-alu0101182773"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.15"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "guard"
27
+ spec.add_development_dependency "guard-rspec"
28
+ spec.add_development_dependency "guard-bundler"
29
+ end
metadata ADDED
@@ -0,0 +1,169 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nutrientes12345
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Malte Bossert
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: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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: This gem includes a class that was built using test-driven development
98
+ with rspec. It can be initialised with a food and its values (in gramms) of macronutrients,
99
+ say Carbohydrates, Fats and Proteins
100
+ email:
101
+ - alu0101182773@ull.edu.es
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Guardfile
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - docs/Alimento.html
116
+ - docs/AlimentosCarbohidratos.html
117
+ - docs/AlimentosGrasos.html
118
+ - docs/CarnesDerivados.html
119
+ - docs/Frutas.html
120
+ - docs/HuevosLacteosHelados.html
121
+ - docs/List.html
122
+ - docs/List/Node.html
123
+ - docs/Nutrientes.html
124
+ - docs/PescadosMariscos.html
125
+ - docs/VerdurasHortalizas.html
126
+ - docs/_index.html
127
+ - docs/class_list.html
128
+ - docs/css/common.css
129
+ - docs/css/full_list.css
130
+ - docs/css/style.css
131
+ - docs/file.README.html
132
+ - docs/file_list.html
133
+ - docs/frames.html
134
+ - docs/index.html
135
+ - docs/js/app.js
136
+ - docs/js/full_list.js
137
+ - docs/js/jquery.js
138
+ - docs/method_list.html
139
+ - docs/top-level-namespace.html
140
+ - lib/jerarquia.rb
141
+ - lib/list.rb
142
+ - lib/nutrientes.rb
143
+ - lib/nutrientes/version.rb
144
+ - lib/plato.rb
145
+ - nutrientes.gemspec
146
+ homepage: https://github.com/ULL-ESIT-LPP-1718/tdd-alu0101182773
147
+ licenses: []
148
+ metadata: {}
149
+ post_install_message:
150
+ rdoc_options: []
151
+ require_paths:
152
+ - lib
153
+ required_ruby_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ requirements: []
164
+ rubyforge_project:
165
+ rubygems_version: 2.5.1
166
+ signing_key:
167
+ specification_version: 4
168
+ summary: Gem to represent foods and their nutrients.
169
+ test_files: []