one44-cli 0.0.4 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e811b1c11362294deaf5030115ca69e848467b1025b17b207c31829d18ed7842
4
- data.tar.gz: b141b078d3932311c52775e8c5e182e8f2685c820952b12b02270e6c1b7b0441
3
+ metadata.gz: be80efae9e104478942b455965752f6f062dd49c84a94a11fff7c5e062039258
4
+ data.tar.gz: ad0eb206e009b087c73545345b3df53cb653e1358d3df50f01ec6e35a85d64cf
5
5
  SHA512:
6
- metadata.gz: b55744031caf87ca56d44754e7620a1e87b2b61d7e4c57ac4a0d2c4f178e98fdb6929e4e6ff107605ba3dc96f5d7d62d0be6c5f12d0b318b1fe30fe9933b4ccd
7
- data.tar.gz: 692ce413ae5a70aa61ccbeb81588b8d7dac04b4bde79ecba2ccd9ac0593d89afc85b0b6e6341f2342eefa76258c0cb4d8e55ec1f77f57958419255f204af5d04
6
+ metadata.gz: 5dc34c9522743cebdb04e4a0cfca23dffe85d7cf82ed70eb029c8c0a98ff0ae76894b3bdb0c586f48a2f06e9d95bbbf2d01f4e0ac00db214a20e9def427b539a
7
+ data.tar.gz: fd166a7d2141cb87322270ac7a99560986e10e6cb4318da1e3362a00aed406edc78e29b303301f937217638e1de83d62af529e4d9ae120c046dbfa9b37b6debc
data/README.md CHANGED
@@ -8,4 +8,20 @@ Install the gem:
8
8
  `gem install one44-cli`
9
9
 
10
10
  ## How to use
11
- $`one44-cli`
11
+
12
+ ### Randomly order test questions (default)
13
+ Test questions are randomly ordered. Make the behaviour explicit by specifying one of the options below:
14
+
15
+ $`one44-cli`
16
+
17
+ $`one44-cli -r`
18
+
19
+ $`one44-cli --random-sort-questions`
20
+
21
+ $`one44-cli --sort-questions random`
22
+
23
+
24
+ ### Do not randomly order test questions
25
+ Test questions will be ordered as listed if the `--not-random-sort-questions` is specified:
26
+
27
+ $`one44-cli --not-random-sort-questions`
data/bin/one44-cli CHANGED
@@ -6,16 +6,19 @@ require 'one44'
6
6
  require 'one44/adaptors/io/cli'
7
7
  require 'one44-cli'
8
8
 
9
-
10
9
  include One44::Adaptors::IO::CLI
10
+ include One44::CLI::Helpers
11
+ include One44::CLI::Optparse
12
+
13
+ test = One44::Test.new($stdout)
11
14
 
12
- test = One44::Test.new(STDOUT)
13
- test.start('indigo', randomise(questions))
15
+ ordered_questions = $one44_cli_options[:question_order] == :random ? randomise(questions) : questions
16
+ test.start('indigo', ordered_questions)
14
17
  test.questions.each_with_index do |_question, index|
15
18
  test.provide clean(answer), index
16
- STDOUT.puts
17
- STDOUT.print "#{test.questions[index + 1]}: " unless test.questions[index] == test.questions.last
19
+ $stdout.puts
20
+ $stdout.print "#{test.questions[index + 1]}: " unless test.questions[index] == test.questions.last
18
21
  end
19
- STDOUT.print 'Result: '
20
- STDOUT.print test.result.to_s
21
- STDOUT.puts
22
+ $stdout.print 'Result: '
23
+ $stdout.print test.result.to_s
24
+ $stdout.puts
data/lib/one44-cli.rb CHANGED
@@ -1,19 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- def answer
4
- gets.chomp
5
- end
6
-
7
- def clean(answer)
8
- Integer(answer).to_i
9
- rescue StandardError
10
- nil
11
- end
12
-
13
- def randomise(questions)
14
- questions.shuffle
15
- end
16
-
17
- def questions
18
- load_tests_from_csv_file('bin/tests/Advanced Indigo.txt', "\t\t")
19
- end
3
+ require_relative 'one44-cli/helpers'
4
+ require_relative 'one44-cli/optparse'
5
+ require_relative 'one44-cli/version'
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module One44
4
+ module CLI
5
+ module Helpers
6
+ def answer
7
+ gets.chomp
8
+ end
9
+
10
+ def clean(answer)
11
+ Integer(answer).to_i
12
+ rescue StandardError
13
+ nil
14
+ end
15
+
16
+ def randomise(questions)
17
+ questions.shuffle
18
+ end
19
+
20
+ def questions
21
+ load_tests_from_csv_file('bin/tests/Advanced Indigo.txt', "\t\t")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module One44
4
+ module CLI
5
+ module Optparse
6
+ require 'optparse'
7
+
8
+ $one44_cli_options = {}
9
+ option_parser = OptionParser.new do |opts|
10
+ opts.on('-r', '--random-sort-questions') do
11
+ $one44_cli_options[:random_sort_questions] = true
12
+ end
13
+
14
+ opts.on('--not-random-sort-questions') do
15
+ $one44_cli_options[:random_sort_questions] = false
16
+ end
17
+
18
+ opts.on('-s ORDER', '--sort-questions=ORDER', /^random$/i) do |order|
19
+ $one44_cli_options[:question_order] = order.downcase.to_sym
20
+ end
21
+ end
22
+ option_parser.parse!
23
+
24
+ unless $one44_cli_options&.dig(:question_order)
25
+ $one44_cli_options[:question_order] = :random unless $one44_cli_options&.dig(:random_sort_questions) == false
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module One44
4
- VERSION = '0.0.4'
4
+ module CLI
5
+ VERSION = '0.1.1'
6
+ end
5
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one44-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bonsu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-10 00:00:00.000000000 Z
11
+ date: 2021-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: one44
@@ -24,7 +24,7 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.2
27
- description: Marks math problems'
27
+ description: Marks math problems
28
28
  email: adam@bonsu.io
29
29
  executables:
30
30
  - one44-cli
@@ -37,6 +37,8 @@ files:
37
37
  - README.md
38
38
  - bin/one44-cli
39
39
  - lib/one44-cli.rb
40
+ - lib/one44-cli/helpers.rb
41
+ - lib/one44-cli/optparse.rb
40
42
  - lib/one44-cli/version.rb
41
43
  homepage: https://github.com/adambonsu/one44-cli
42
44
  licenses: