ull-etsii-alu4321-quiz 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,19 @@
1
1
  *.gem
2
+ *.rbc
2
3
  .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
3
8
  Gemfile.lock
4
9
  pkg/*
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in ull-etsii-alu4321-quiz.gemspec
4
4
  gemspec
5
-
data/Guardfile ADDED
@@ -0,0 +1,5 @@
1
+ guard 'rspec' do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,15 @@
1
+ DSL (Domaing Specific Lenguage) para RedacciC3n de Custionarios (Sin Contexto)
2
+ Copyright (c) 2012 katerine
3
+
4
+ This program is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ This program is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU General Public License for more details.
13
+
14
+ You should have received a copy of the GNU General Public License
15
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Practica 12 cuestionaros con contexto
data/Rakefile CHANGED
@@ -1,11 +1,6 @@
1
1
  $:.unshift File.dirname(__FILE__) + 'lib'
2
- require "bundler"
2
+ require "bundler/gem_tasks"
3
+
3
4
  require 'rspec/core/rake_task'
4
- Bundler::GemHelper.install_taskswe can take a look at those task by running rake-T
5
5
  RSpec::Core::RakeTask.new
6
- task :default => :spec
7
-
8
- desc "Genera la documentaciC3n de la GEM"
9
- task :rdoc do
10
- sh 'rdoc --exclude Gemfile --exclude Guardfile --exclude Rakefile --exclude rspec_*'
11
- end
6
+ task :default => :spec
data/bin/quiz.rb ADDED
@@ -0,0 +1,21 @@
1
+ #encoding: UTF-8
2
+ require 'ull:etsii:alu4321::quiz'
3
+ include Ull::Etsii::Alu4321::Quiz
4
+
5
+ quiz = Quiz.new("preguntas al asar") {
6
+ question "en que aC1o cristobal colon descubrio america?",
7
+ e.right => "1492",
8
+ e.wrong => "1942",
9
+ e.wrong => "1808",
10
+ e.wrong => "1914"
11
+
12
+ a=rand(10)
13
+ b=rand(10)
14
+ question "#{a}+B7{b}=?",
15
+ e.wrong => "44",
16
+ e.wrong => "#{a+b+2}",
17
+ e.right => "#{a+b}",
18
+ e.wrong => "#{a+b-2}"
19
+ }
20
+
21
+ quiz.run
@@ -1,170 +1,10 @@
1
1
  require "ull-etsii-alu4321-quiz/version"
2
- require 'colorize'
3
- require 'erb'
2
+ require "ull-etsii-alu4321-quiz/quiz"
3
+
4
4
  module Ull
5
5
  module Etsii
6
6
  module Alu4321
7
- module Quiz
8
-
9
- WRONG = false
10
- RIGHT = true
11
-
12
- # Clase que permite la construcciC3n de cuestionarios tipo test mediante un DSL
13
- class Quiz
14
- attr_accessor :name, :questions
15
-
16
- # Recibe el nombre del test y un bloque con las preguntas y sus respuestas
17
- #
18
- # Ejemplo de uso:
19
- # quiz = Quiz.new("Test 1"){ |e|
20
- # e.question "Pregunta 1",
21
- # e.wrong => "Respuesta incorrecta 1",
22
- # e.wrong => "Respuesta incorrecta 2",
23
- # e.wrong => "Respuesta incorrecta 3",
24
- # e.rigth => "Respuesta correcta"
25
- # }
26
- def initialize(name)
27
- @counter = 0
28
- @aciertos = 0
29
- @name = name
30
- @questions = []
31
-
32
- yield self
33
- end
34
-
35
- # Pregunta incorrecta
36
- #
37
- # Avoid collisions
38
- def wrong
39
- @counter += 1
40
- [@counter, WRONG]
41
- end
42
-
43
- # Pregunta correcta
44
- def right
45
- :right
46
- end
47
-
48
- # MC)todo que recibe el tC-tulo <em>title</em> de la pregunta y una serie de
49
- # parC!metros como respuestas
50
- def question(title, anss)
51
- answers = []
52
-
53
- anss.each do |ans|
54
- a = Answer.new(ans)
55
- answers << a
56
- end
57
-
58
- q = Question.new(title, answers)
59
- questions << q
60
- end
61
-
62
- # Ejecuta el test por consola. Presenta cada pregunta y las posibles respuestas.
63
- # Al final muestra los resultados.
64
- def run
65
- puts name
66
- questions.each do |q|
67
- puts q
68
- print "Su respuesta: "
69
- resp = gets.chomp.to_i
70
- raise IndexError, "Answer must be between 1 and #{q.answers.size}." unless resp <= q.answers.size and resp > 0
71
- if q.answers[resp-1].state
72
- puts "Correcto!".colorize(:light_green)
73
- @aciertos += 1
74
- else
75
- correcta = q.answers.select { |ans| ans.state }.first
76
- puts "Fallo, la respuesta correcta era #{correcta}".colorize(:red)
77
- end
78
- puts
79
- end
80
- puts "Has acertado el #{(@aciertos/questions.size.to_f)*100}% de las preguntas [#{@aciertos} de #{questions.size}]."
81
- end
82
-
83
- # RepresentaciC3n visual de un Test en forma de String.
84
- def to_s
85
- out = name + "\n"
86
- questions.each do |q|
87
- out << "#{q}\n"
88
- end
89
- out
90
- end
91
-
92
- # Genera el test en formato html.
93
- # Dicho test es totalmente funcional, permitiendo la selecciC3n de respuestas y
94
- # la correcciC3n de las mismas
95
- def to_html
96
- # SetUp del fichero de salida
97
- if not Dir.exist? "html"
98
- # Copiamos el directorio html con los ficheros bC!sicos
99
- require 'fileutils'
100
- FileUtils.cp_r File.expand_path(File.dirname(__FILE__)) + '/html', 'html'
101
- end
102
- # Generamos HTML
103
- htmlFile = File.new("html/#{name.gsub(/[\ \\\/:]/, '_')}.html", "w")
104
- raise IOError, 'Can\'t access to html output file' unless htmlFile
105
- # Generamos JavaScript
106
- jsFile = File.new("html/js/quiz.js", "w")
107
- raise IOError, 'Can\'t access to javascript output file' unless jsFile
108
-
109
- # Construimos los ERB y los escribimos en los ficheros
110
- require 'templates'
111
- rhtml = ERB.new(HTML_TEMPLATE)
112
- htmlFile.syswrite(rhtml.result(binding))
113
- htmlFile.close
114
-
115
- rjs = ERB.new(JAVASCRIPT_TEMPLATE)
116
- jsFile.syswrite(rjs.result(binding))
117
- jsFile.close
118
-
119
-
120
- end
121
-
122
- end
123
-
124
- # Clase que representa una de pregunta a un test.
125
- class Question
126
- attr_accessor :answers, :title
127
- # Recibe un tC-tulo <em>title</em> de la pregunta y el resto de parC!metros son las
128
- # posibles respuestas.
129
- def initialize(title, anss)
130
- raise ArgumentError, "Title has to be a String, got #{title.class}" unless title.is_a? String
131
- @title = title
132
- @answers = anss
133
- end
134
-
135
- # RepresentaciC3n visual de una pregunta en forma de String.
136
- def to_s
137
- out = "# #{@title}".colorize(:light_blue) + "\n"
138
- i = 1
139
- answers.each do |a|
140
- out << " [#{i}] #{a}\n"
141
- i += 1
142
- end
143
- out
144
- end
145
- end
146
-
147
- # Clase que representa las respuestas a preguntas de un test.
148
- class Answer
149
- attr_reader :state, :value
150
-
151
- # Recibe como parC!metro una lista de dos elementos que contiene
152
- # el <em>state</em> o estado de la respuesta (si es verdadera o falsa)
153
- # y el <em>value</em> con el texto que la representa.
154
- def initialize(ans)
155
- raise ArgumentError, "Array spected, got #{ans.class}" unless ans.is_a? Array
156
- raise IndexError, 'Must have two (2) elements; state and value' unless ans.size == 2
157
- state = ans[0]
158
- value = ans[1]
159
- state == :right ? @state = RIGHT : @state = WRONG
160
- @value = value
161
- end
162
-
163
- # Devuelve <em>value</em>, es decir, el texto que describe a la respuesta
164
- def to_s
165
- "#{@value}"
166
- end
167
- end
7
+ module Quiz
168
8
  end
169
9
  end
170
10
  end
@@ -0,0 +1,175 @@
1
+ #encoding: UTF-8
2
+ require "ULL-ETSII-Alu4321-Quiz/version"
3
+ require 'colorize'
4
+ require 'erb'
5
+
6
+ module ULL
7
+ module ETSII
8
+ module Alu4321
9
+ module Quiz
10
+
11
+ WRONG = false
12
+ RIGHT = true
13
+
14
+ # Clase que permite la construcciC3n de cuestionarios tipo test mediante un DSL
15
+ class Quiz
16
+ attr_accessor :name, :questions
17
+
18
+ # Recibe el nombre del test y un bloque con las preguntas y sus respuestas
19
+ #
20
+ # Ejemplo de uso:
21
+ # quiz = Quiz.new("Test 1"){
22
+ # question "Pregunta 1",
23
+ # wrong => "Respuesta incorrecta 1",
24
+ # wrong => "Respuesta incorrecta 2",
25
+ # wrong => "Respuesta incorrecta 3",
26
+ # right => "Respuesta correcta"
27
+ # }
28
+ def initialize(name, &block)
29
+ @counter = 0
30
+ @aciertos = 0
31
+ @name = name
32
+ @questions = []
33
+
34
+ instance_eval &block
35
+ end
36
+
37
+ # Pregunta incorrecta
38
+ #
39
+ # Avoid collisions
40
+ def wrong
41
+ @counter += 1
42
+ [@counter, WRONG]
43
+ end
44
+
45
+ # Pregunta correcta
46
+ def right
47
+ :right
48
+ end
49
+
50
+ # MC)todo que recibe el tC-tulo <em>title</em> de la pregunta y una serie de
51
+ # parC!metros como respuestas
52
+ def question(title, anss)
53
+ answers = []
54
+
55
+ anss.each do |ans|
56
+ a = Answer.new(ans)
57
+ answers << a
58
+ end
59
+
60
+ q = Question.new(title, answers)
61
+ questions << q
62
+ end
63
+
64
+ # Ejecuta el test por consola. Presenta cada pregunta y las posibles respuestas.
65
+ # Al final muestra los resultados.
66
+ def run
67
+ aciertos = 0
68
+ puts name
69
+ questions.each do |q|
70
+ puts q
71
+ print "Su respuesta: "
72
+ resp = gets.chomp.to_i
73
+ raise IndexError, "Answer must be between 1 and #{q.answers.size}." unless resp <= q.answers.size and resp > 0
74
+ if q.answers[resp-1].state
75
+ puts "Correcto!".colorize(:light_green)
76
+ @aciertos += 1
77
+ else
78
+ correcta = q.answers.select { |ans| ans.state }.first
79
+ puts "Fallo, la respuesta correcta era #{correcta}".colorize(:red)
80
+ end
81
+ puts
82
+ end
83
+ puts "Has acertado el #{(@aciertos/questions.size.to_f)*100}% de las preguntas [#{@aciertos} de #{questions.size}]."
84
+ end
85
+
86
+ # RepresentaciC3n visual de un Test en forma de String.
87
+ def to_s
88
+ out = name + "\n"
89
+ questions.each do |q|
90
+ out << "#{q}\n"
91
+ end
92
+ out
93
+ end
94
+
95
+ # Genera el test en formato html.
96
+ # Dicho test es totalmente funcional, permitiendo la selecciC3n de respuestas y
97
+ # la correcciC3n de las mismas
98
+ def to_html
99
+ # SetUp del fichero de salida
100
+ if not Dir.exist? "html"
101
+ # Copiamos el directorio html con los ficheros bC!sicos
102
+ require 'fileutils'
103
+ FileUtils.cp_r File.expand_path(File.dirname(__FILE__)) + '/html', 'html'
104
+ end
105
+ # Generamos HTML
106
+ htmlFile = File.new("html/#{name.gsub(/[\ \\\/:]/, '_')}.html", "w")
107
+ raise IOError, 'Can\'t access to html output file' unless htmlFile
108
+ # Generamos JavaScript
109
+ jsFile = File.new("html/js/quiz.js", "w")
110
+ raise IOError, 'Can\'t access to javascript output file' unless jsFile
111
+
112
+ # Construimos los ERB y los escribimos en los ficheros
113
+ require 'templates'
114
+ rhtml = ERB.new(HTML_TEMPLATE)
115
+ htmlFile.syswrite(rhtml.result(binding))
116
+ htmlFile.close
117
+
118
+ rjs = ERB.new(JAVASCRIPT_TEMPLATE)
119
+ jsFile.syswrite(rjs.result(binding))
120
+ jsFile.close
121
+
122
+
123
+ end
124
+
125
+ end
126
+
127
+ # Clase que representa una de pregunta a un test.
128
+ class Question
129
+ attr_accessor :answers, :title
130
+ # Recibe un tC-tulo <em>title</em> de la pregunta y el resto de parC!metros son las
131
+ # posibles respuestas.
132
+ def initialize(title, anss)
133
+ raise ArgumentError, "Title has to be a String, got #{title.class}" unless title.is_a? String
134
+ @title = title
135
+ @answers = anss
136
+ end
137
+
138
+ # RepresentaciC3n visual de una pregunta en forma de String.
139
+ def to_s
140
+ out = "# #{@title}".colorize(:light_blue) + "\n"
141
+ i = 1
142
+ answers.each do |a|
143
+ out << " [#{i}] #{a}\n"
144
+ i += 1
145
+ end
146
+ out
147
+ end
148
+ end
149
+
150
+ # Clase que representa las respuestas a preguntas de un test.
151
+ class Answer
152
+ attr_reader :state, :value
153
+
154
+ # Recibe como parC!metro una lista de dos elementos que contiene
155
+ # el <em>state</em> o estado de la respuesta (si es verdadera o falsa)
156
+ # y el <em>value</em> con el texto que la representa.
157
+ def initialize(ans)
158
+ raise ArgumentError, "Array spected, got #{ans.class}" unless ans.is_a? Array
159
+ raise IndexError, 'Must have two (2) elements; state and value' unless ans.size == 2
160
+ state = ans[0]
161
+ value = ans[1]
162
+ state == :right ? @state = RIGHT : @state = WRONG
163
+ @value = value
164
+ end
165
+
166
+ # Devuelve <em>value</em>, es decir, el texto que describe a la respuesta
167
+ def to_s
168
+ "#{@value}"
169
+ end
170
+ end
171
+
172
+ end
173
+ end
174
+ end
175
+
@@ -2,7 +2,7 @@ module Ull
2
2
  module Etsii
3
3
  module Alu4321
4
4
  module Quiz
5
- VERSION = "0.0.1"
5
+ VERSION = "1.0.0"
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,35 @@
1
+ #encoding: UTF-8
2
+ require 'ULL::ETSII::Alu4321::Quiz'
3
+
4
+ include ULL::ETSII::Alu4321::Quiz
5
+
6
+ describe Quiz do
7
+
8
+ before :all do
9
+ @quiz = Quiz.new("test"){ |e|
10
+ e.question "Pregunta 1",
11
+ e.right => "Answer 1" ,
12
+ e.wrong => "Answer2"
13
+ }
14
+ end
15
+
16
+ it "Debe tener un mC)todo 'question' para declarar preguntas" do
17
+ (@quiz.respond_to? :question).should == true
18
+ end
19
+
20
+ it "Debe tener un mC)todo 'wrong' para declarar respuestas errC3neas" do
21
+ (@quiz.respond_to? :wrong).should == true
22
+ end
23
+
24
+ it "Debe tener un mC)todo 'right' para declarar la respuesta correcta" do
25
+ (@quiz.respond_to? :right).should == true
26
+ end
27
+
28
+ it "Debe tener un mC)todo 'run' que ejecuta el test" do
29
+ (@quiz.respond_to? :run).should == true
30
+ end
31
+
32
+ it "Debe tener un mC)todo 'to_s'" do
33
+ (@quiz.respond_to? :to_s).should == true
34
+ end
35
+ end
@@ -18,4 +18,4 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ull-etsii-alu4321-quiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,15 +14,22 @@ dependencies: []
14
14
  description: ! ' redatar cuestionarios'
15
15
  email:
16
16
  - katerine_cardona@hotmail.com
17
- executables: []
17
+ executables:
18
+ - quiz.rb
18
19
  extensions: []
19
20
  extra_rdoc_files: []
20
21
  files:
21
22
  - .gitignore
22
23
  - Gemfile
24
+ - Guardfile
25
+ - LICENSE.txt
26
+ - README.md
23
27
  - Rakefile
28
+ - bin/quiz.rb
24
29
  - lib/ull-etsii-alu4321-quiz.rb
30
+ - lib/ull-etsii-alu4321-quiz/quiz.rb
25
31
  - lib/ull-etsii-alu4321-quiz/version.rb
32
+ - spec/ull::etsii:alu4321::quiz_spec.rb
26
33
  - ull-etsii-alu4321-quiz.gemspec
27
34
  homepage: ''
28
35
  licenses: []