whatisquiz 0.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/bin/whatisquiz +79 -54
- data/lib/color.rb +30 -0
- data/lib/default_config +19 -0
- data/lib/read_config.rb +26 -0
- data/lib/whatisquiz/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 66d9a528994c9da30791ef85f5b8351abe0375c1
|
|
4
|
+
data.tar.gz: 198ea471eaa3e0367874fbdd1f8842a0a881b8b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 08b2f3dc3a5ad59d90300b47d76c954cd88cf531db5559f29db9fe87f6f31abf45211d68c201b548670d5f4eb56644d327a2b38deb8df53c0641a2bf214ca2f7
|
|
7
|
+
data.tar.gz: 79475dca68da8bd34b6968339663f0be4d0e23f8c98750de6d5ffba2f1436f318dad2ff402e7e32234b98160d4c8a232401ba23d3525aa1d8140419ff73f02ff
|
data/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Whatisquiz
|
|
2
2
|
|
|
3
3
|
*whatisquiz* is a command-line program to enjoy unix command quiz.
|
|
4
|
+
|
|
4
5
|
## Installation
|
|
5
6
|
|
|
6
7
|
To install it, type:
|
|
@@ -12,9 +13,14 @@ To install it, type:
|
|
|
12
13
|
On your terminal, just type *whatisquiz*
|
|
13
14
|
then, start a quiz.
|
|
14
15
|
|
|
16
|
+
## Settings
|
|
17
|
+
|
|
18
|
+
you can add your bin path to use generating quiz database.
|
|
19
|
+
set your own settings in .whatisquiz/config.
|
|
20
|
+
|
|
15
21
|
## Contributing
|
|
16
22
|
|
|
17
|
-
1. Fork it ( https://github.com/
|
|
23
|
+
1. Fork it ( https://github.com/chakirin/whatisquiz/fork )
|
|
18
24
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
19
25
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
20
26
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/bin/whatisquiz
CHANGED
|
@@ -1,17 +1,53 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
require 'csv'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require_relative '../lib/read_config.rb'
|
|
5
|
+
require_relative '../lib/color.rb'
|
|
3
6
|
|
|
4
7
|
$HOME = Dir.home
|
|
5
|
-
$DB_PATH = Dir.home + '/.whatisquiz/db'
|
|
8
|
+
$DB_PATH = Dir.home + '/.whatisquiz/db/quizdb.csv'
|
|
9
|
+
$CONFIG_PATH = Dir.home + '/.whatisquiz/config'
|
|
10
|
+
$header=<<EOF
|
|
11
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
12
|
+
% %%% %%%% %%%% %%%%% %%%%%%%% %%%%%%%% %%%%% %%%% %%
|
|
13
|
+
% %%% %%%% %%%% %%%%% %%%%%%% %% %%%%%%%%%%% %%%%%%%%%%%% %%%%%% %%%%%%%
|
|
14
|
+
%% % % % %%%%% %%%%% %%%%%%%%% %%%%%%%%%%%% %%%%%%%% %%%%
|
|
15
|
+
%% % % % %%%%% %%%%% %%%% %%%%%%% %%%%%%%% %%%%%%%%%%%% %%%%%%%%%% %%
|
|
16
|
+
%%% %%%% %%%%%%% %%%%% %%% %%%%%%%%% %%%%%%% %%%%%%%%% %%%% %%%
|
|
17
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
18
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
19
|
+
%%%%%%%%%%%%% %%%%%%% %%%%%%% %%%%%% %%%%%% %%%%%%%%%%%%%%%%%
|
|
20
|
+
%%%%%%%%%%%% %%%%%% %%%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%
|
|
21
|
+
%%%%%%%%%%% %%%%%%%% %%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%
|
|
22
|
+
%%%%%%%%%%% %%%%%%%% %%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%
|
|
23
|
+
%%%%%%%%%%% %%%%% %% %%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%
|
|
24
|
+
%%%%%%%%%%%% %%%%% %%%%%%% %%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%
|
|
25
|
+
%%%%%%%%%%%%% % %%%%%%% %%%%%%%% %%%%%% %%%%%%%%%%%%%%%%%
|
|
26
|
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
27
|
+
EOF
|
|
28
|
+
$design=<<EOF
|
|
29
|
+
###################################################################
|
|
30
|
+
EOF
|
|
6
31
|
|
|
32
|
+
$helpstr=<<EOF
|
|
33
|
+
.-----------------------------------.
|
|
34
|
+
| init: recreate database for quiz |
|
|
35
|
+
| quit: exit the game |
|
|
36
|
+
| help: show commands |
|
|
37
|
+
*-----------------------------------*
|
|
38
|
+
EOF
|
|
39
|
+
$config = Reader.new
|
|
7
40
|
def create_dict
|
|
8
41
|
commands = Array.new
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
42
|
+
$config.path.each do |path|
|
|
43
|
+
Dir.open(path) do |dir|
|
|
44
|
+
dir.each do |name|
|
|
45
|
+
commands << name
|
|
46
|
+
end
|
|
12
47
|
end
|
|
13
48
|
end
|
|
14
|
-
|
|
49
|
+
commands.uniq!
|
|
50
|
+
CSV.open($DB_PATH, "w") do |line|
|
|
15
51
|
commands.each do |cmd|
|
|
16
52
|
`whatis #{cmd}` =~ /- (.*) *$/
|
|
17
53
|
next if $1 == nil
|
|
@@ -21,59 +57,16 @@ def create_dict
|
|
|
21
57
|
end
|
|
22
58
|
|
|
23
59
|
def repl
|
|
24
|
-
header=<<EOF
|
|
25
|
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
26
|
-
% %%% %%%% %%%% %%%%% %%%%%%%% %%%%%%%% %%%%% %%%% %%
|
|
27
|
-
% %%% %%%% %%%% %%%%% %%%%%%% %% %%%%%%%%%%% %%%%%%%%%%%% %%%%%% %%%%%%%
|
|
28
|
-
%% % % % %%%%% %%%%% %%%%%%%%% %%%%%%%%%%%% %%%%%%%% %%%%
|
|
29
|
-
%% % % % %%%%% %%%%% %%%% %%%%%%% %%%%%%%% %%%%%%%%%%%% %%%%%%%%%% %%
|
|
30
|
-
%%% %%%% %%%%%%% %%%%% %%% %%%%%%%%% %%%%%%% %%%%%%%%% %%%% %%%
|
|
31
|
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
32
|
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
33
|
-
%%%%%%%%%%% %%%%%%% %%%%%%% %%%%%% %%%%%% %%%%%%%%%%%%%%%%%%%
|
|
34
|
-
%%%%%%%%%% %%%%%% %%%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%
|
|
35
|
-
%%%%%%%%% %%%%%%%% %%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%
|
|
36
|
-
%%%%%%%%% %%%%%%%% %%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
|
|
37
|
-
%%%%%%%%% %%%%% %% %%%%% %%%%%%% %%%%%%%%% %%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%
|
|
38
|
-
%%%%%%%%%% %%%%% %%%%%%% %%%%% %%%%%%%%%% %%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%
|
|
39
|
-
%%%%%%%%%%% % %%%%%%% %%%%%%%% %%%%%% %%%%%%%%%%%%%%%%%%%
|
|
40
|
-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
41
|
-
EOF
|
|
42
|
-
design=<<-EOF
|
|
43
|
-
######################################
|
|
44
|
-
EOF
|
|
45
|
-
|
|
46
|
-
helpstr=<<EOF
|
|
47
|
-
.----------------------------------.
|
|
48
|
-
|init: recreate database for quiz |
|
|
49
|
-
|quit: exit the game |
|
|
50
|
-
|help: show commands |
|
|
51
|
-
*----------------------------------*
|
|
52
|
-
EOF
|
|
53
|
-
prompt = '$ '
|
|
54
|
-
puts header
|
|
55
|
-
if Dir.glob($DB_PATH + "/quizdb.csv").empty?
|
|
56
|
-
puts "database not found"
|
|
57
|
-
puts "initialize setup..."
|
|
58
|
-
Dir.mkdir(Dir.home + '/.whatisquiz', mode = 0777)
|
|
59
|
-
Dir.mkdir($DB_PATH, mode = 0777)
|
|
60
|
-
create_dict
|
|
61
|
-
print "\n\n\n\n\n\n"
|
|
62
|
-
puts "welcome whatisquiz!!"
|
|
63
|
-
puts "whatisquiz is a quiz about unix command"
|
|
64
|
-
puts helpstr
|
|
65
|
-
print "\n\n\n"
|
|
66
|
-
end
|
|
67
60
|
db = Array.new
|
|
68
|
-
CSV.foreach($DB_PATH
|
|
61
|
+
CSV.foreach($DB_PATH) do |row|
|
|
69
62
|
db << row
|
|
70
63
|
end
|
|
71
64
|
|
|
72
65
|
while true
|
|
73
|
-
randarr = (
|
|
74
|
-
puts design
|
|
66
|
+
randarr = (0..File.read($DB_PATH).count("\n")-1).to_a.shuffle!
|
|
67
|
+
puts $design
|
|
75
68
|
puts ' ' + db[randarr[0]][1]
|
|
76
|
-
puts design
|
|
69
|
+
puts $design
|
|
77
70
|
ans = db[randarr[0]][0]
|
|
78
71
|
nans1 = db[randarr[1]][0]
|
|
79
72
|
nans2 = db[randarr[2]][0]
|
|
@@ -82,11 +75,13 @@ EOF
|
|
|
82
75
|
printf("%20s%20s\n", selecters[0], selecters[1])
|
|
83
76
|
printf("%20s%20s\n", selecters[2], selecters[3])
|
|
84
77
|
puts "input your answer"
|
|
85
|
-
|
|
78
|
+
Color.set($config.color[:prompt])
|
|
79
|
+
print $config.prompt
|
|
80
|
+
Color.set('reset')
|
|
86
81
|
input = gets.chomp
|
|
87
82
|
case input
|
|
88
83
|
when "help"
|
|
89
|
-
puts helpstr
|
|
84
|
+
puts $helpstr
|
|
90
85
|
gets
|
|
91
86
|
when "quit"
|
|
92
87
|
puts "see you again"
|
|
@@ -94,12 +89,42 @@ EOF
|
|
|
94
89
|
when "init"
|
|
95
90
|
create_dict
|
|
96
91
|
when db[randarr[0]][0]
|
|
92
|
+
Color.set($config.color[:great])
|
|
97
93
|
puts "great!\n"
|
|
94
|
+
Color.set('reset')
|
|
98
95
|
else
|
|
96
|
+
Color.set($config.color[:miss])
|
|
99
97
|
puts "miss..."
|
|
100
98
|
puts "the answer is " + ans
|
|
99
|
+
Color.set('reset')
|
|
101
100
|
puts "\n"
|
|
102
101
|
end
|
|
103
102
|
end
|
|
104
103
|
end
|
|
104
|
+
|
|
105
|
+
def conf_init
|
|
106
|
+
if Dir.glob($CONFIG_PATH).empty?
|
|
107
|
+
FileUtils.mkdir_p($HOME + '/.whatisquiz')
|
|
108
|
+
puts 'generating config file...'
|
|
109
|
+
`cp lib/default_config $HOME/.whatisquiz/config`
|
|
110
|
+
else
|
|
111
|
+
$config.instance_eval File.read($CONFIG_PATH), $CONFIG_PATH
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
if Dir.glob($DB_PATH).empty?
|
|
115
|
+
puts "database not found"
|
|
116
|
+
puts "initialize setup..."
|
|
117
|
+
FileUtils.mkdir_p(Dir.home + '/.whatisquiz/db')
|
|
118
|
+
create_dict
|
|
119
|
+
print "\n\n\n\n\n\n"
|
|
120
|
+
puts "welcome whatisquiz!!"
|
|
121
|
+
puts "whatisquiz is a quiz about unix command"
|
|
122
|
+
puts $helpstr
|
|
123
|
+
print "\n\n\n"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
Color.set('reset')
|
|
127
|
+
puts $header
|
|
128
|
+
puts "\n"
|
|
129
|
+
conf_init
|
|
105
130
|
repl
|
data/lib/color.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
class Color
|
|
4
|
+
class << self
|
|
5
|
+
def set(str)
|
|
6
|
+
case str
|
|
7
|
+
when 'reset'
|
|
8
|
+
c 0
|
|
9
|
+
when 'red'
|
|
10
|
+
c 31
|
|
11
|
+
when 'green'
|
|
12
|
+
c 32
|
|
13
|
+
when 'yellow'
|
|
14
|
+
c 33
|
|
15
|
+
when 'blue'
|
|
16
|
+
c 34
|
|
17
|
+
when 'magenta'
|
|
18
|
+
c 35
|
|
19
|
+
when 'cyan'
|
|
20
|
+
c 36
|
|
21
|
+
when 'white'
|
|
22
|
+
c 37
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
def c(num)
|
|
26
|
+
print "\e[#{num.to_s}m"
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
data/lib/default_config
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
## this is config file.
|
|
2
|
+
# you can change your bin path, prompt, prompt color.
|
|
3
|
+
|
|
4
|
+
## PATH is used for creating quiz database
|
|
5
|
+
## it can create your own quiz.
|
|
6
|
+
## shell like syntax
|
|
7
|
+
## ex) setpath '/bin:/usr/bin'
|
|
8
|
+
setpath '/bin'
|
|
9
|
+
|
|
10
|
+
## you can change the prompt
|
|
11
|
+
## ex) setprompt 'you> '
|
|
12
|
+
setprompt '$ '
|
|
13
|
+
|
|
14
|
+
## you can change the color(red, blue, green, yellow, magenta, cyan, white)
|
|
15
|
+
## ex) setcolor 'prompt', 'red'
|
|
16
|
+
## ex) setcolor 'great', 'blue'
|
|
17
|
+
setcolor 'prompt', 'white'
|
|
18
|
+
setcolor 'great', 'red'
|
|
19
|
+
setcolor 'miss', 'blue'
|
data/lib/read_config.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
class Reader
|
|
4
|
+
attr_reader :path, :prompt, :color
|
|
5
|
+
def initialize
|
|
6
|
+
@path = ["/bin"]
|
|
7
|
+
@prompt = "$ "
|
|
8
|
+
@color = {:prompt => 'white', :great => 'red', :miss => 'blue'}
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def setpath(str)
|
|
12
|
+
if str.index(':')
|
|
13
|
+
@path = str.split(':')
|
|
14
|
+
else
|
|
15
|
+
@path = [str]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def setprompt(str)
|
|
20
|
+
@prompt = str
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def setcolor(arg1, arg2)
|
|
24
|
+
@color[arg1] = arg2
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/whatisquiz/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: whatisquiz
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- chakirin
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-01-
|
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -52,6 +52,9 @@ files:
|
|
|
52
52
|
- README.md
|
|
53
53
|
- Rakefile
|
|
54
54
|
- bin/whatisquiz
|
|
55
|
+
- lib/color.rb
|
|
56
|
+
- lib/default_config
|
|
57
|
+
- lib/read_config.rb
|
|
55
58
|
- lib/whatisquiz.rb
|
|
56
59
|
- lib/whatisquiz/version.rb
|
|
57
60
|
- test/helper.rb
|