whatisquiz 1.0.6 → 1.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d78d399e876c405f34c351813e2e8da566467d0f
4
- data.tar.gz: a9cf1599bf0671d7ce568109ce8bc686da19b707
3
+ metadata.gz: 1810e306e75a9b9aa2b3a6f59f884b361010d779
4
+ data.tar.gz: eb23f7949060d8750398c799b1d5f6835cf76ae2
5
5
  SHA512:
6
- metadata.gz: 77bcc10677853b7f7fdafec0a2b4a2b84bdc0e93dca26eb4249e2c9d53922ea37f3cab82ed8f28db1a82b29baee2f1465a35fdbae14dd63bd900bf5da314cc65
7
- data.tar.gz: 979a766b8019f287719aba34d7f1f4f85d72c8d6bfd256e0316d519b10afd8b55f09b50e0cd50045cf1e527b51033574c714d54cd015f5536d3c98a6e138d37d
6
+ metadata.gz: 49ec968693650dcd0b9e04973fdd39856fe592490613e74b883e6565881fb670d7bc3d23f1e8df0608fa535f779699283389c114cf9d5e4bd804d2e55ffa8654
7
+ data.tar.gz: 61c21145f24988b3edb40518dbcf84644df57490f8bf5eda15fe5a3df606496c798fd755397c992d1eee0cee6a752f08dbd6200c049747210c3d8c3475289216
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in whatisquiz.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 chakirin
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # Whatisquiz
2
+
3
+ *whatisquiz* is a command-line program to enjoy unix command quiz.
4
+
5
+ ## Installation
6
+
7
+ To install it, type:
8
+
9
+ $ gem install whatisquiz
10
+
11
+ ## Usage
12
+
13
+ On your terminal, just type *whatisquiz*
14
+ then, start a quiz.
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
+
21
+ ## Contributing
22
+
23
+ 1. Fork it ( https://github.com/chikyukotei/whatisquiz/fork )
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/whatisquiz ADDED
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+ require 'csv'
3
+ require 'fileutils'
4
+ require_relative '../lib/read_config.rb'
5
+ require_relative '../lib/color.rb'
6
+
7
+ $HOME = Dir.home
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
31
+ $helpstr=<<EOF
32
+ .-----------------------------------.
33
+ | init: recreate database for quiz |
34
+ | quit: exit the game |
35
+ | help: show commands |
36
+ *-----------------------------------*
37
+ EOF
38
+ $default_config=<<EOF
39
+ ## this is config file.
40
+ # you can change your bin path, prompt, prompt color.
41
+
42
+ ## PATH is used for creating quiz database
43
+ ## it can create your own quiz.
44
+ ## shell like syntax
45
+ ## ex) setpath '/bin:/usr/bin'
46
+ setpath '/bin'
47
+
48
+ ## you can change the prompt
49
+ ## ex) setprompt 'you> '
50
+ setprompt '$ '
51
+
52
+ ## you can change the color(red, blue, green, yellow, magenta, cyan, white)
53
+ ## ex) setcolor 'prompt', 'red'
54
+ ## ex) setcolor 'great', 'blue'
55
+ setcolor 'prompt', 'white'
56
+ setcolor 'great', 'red'
57
+ setcolor 'miss', 'blue'
58
+ EOF
59
+ $config = Reader.new
60
+ def create_dict
61
+ commands = Array.new
62
+ $config.path.each do |path|
63
+ Dir.open(path) do |dir|
64
+ dir.each do |name|
65
+ commands << name
66
+ end
67
+ end
68
+ end
69
+ commands.uniq!
70
+ CSV.open($DB_PATH, "w") do |line|
71
+ commands.each do |cmd|
72
+ `whatis #{cmd}` =~ /- (.*) *$/
73
+ next if $1 == nil
74
+ line << [cmd, $1]
75
+ end
76
+ end
77
+ end
78
+
79
+ def repl
80
+ db = Array.new
81
+ CSV.foreach($DB_PATH) do |row|
82
+ db << row
83
+ end
84
+ while true
85
+ randarr = (0..File.read($DB_PATH).count("\n")-1).to_a.shuffle!
86
+ puts $design
87
+ puts db[randarr[0]][1]
88
+ puts $design
89
+ ans = db[randarr[0]][0]
90
+ nans1 = db[randarr[1]][0]
91
+ nans2 = db[randarr[2]][0]
92
+ nans3 = db[randarr[3]][0]
93
+ selecters = [ans,nans1,nans2,nans3].shuffle!
94
+ printf("%20s%20s\n", selecters[0], selecters[1])
95
+ printf("%20s%20s\n", selecters[2], selecters[3])
96
+ puts "input your answer"
97
+ Color.set($config.color["prompt"])
98
+ print $config.prompt
99
+ Color.set('reset')
100
+ input = gets.chomp
101
+ case input
102
+ when "help"
103
+ puts $helpstr
104
+ gets
105
+ when "quit"
106
+ puts "see you again"
107
+ exit
108
+ when "init"
109
+ create_dict
110
+ CSV.foreach($DB_PATH) do |row|
111
+ db << row
112
+ end
113
+ when db[randarr[0]][0]
114
+ Color.set($config.color["great"])
115
+ puts "great!\n"
116
+ Color.set('reset')
117
+ else
118
+ Color.set($config.color["miss"])
119
+ puts "miss..."
120
+ puts "the answer is " + ans
121
+ Color.set('reset')
122
+ puts "\n"
123
+ end
124
+ end
125
+ end
126
+
127
+ def conf_init
128
+ if Dir.glob($CONFIG_PATH).empty?
129
+ FileUtils.mkdir_p($HOME + '/.whatisquiz')
130
+ puts 'generating config file...'
131
+ File.write($CONFIG_PATH, $default_config)
132
+ else
133
+ $config.instance_eval File.read($CONFIG_PATH), $CONFIG_PATH
134
+ end
135
+
136
+ if Dir.glob($DB_PATH).empty?
137
+ puts "database not found"
138
+ puts "initialize setup..."
139
+ FileUtils.mkdir_p(Dir.home + '/.whatisquiz/db')
140
+ create_dict
141
+ print "\n\n\n\n\n\n"
142
+ puts "welcome whatisquiz!!"
143
+ puts "whatisquiz is a quiz about unix command"
144
+ puts $helpstr
145
+ print "\n\n\n"
146
+ end
147
+ end
148
+ Color.set('reset')
149
+ puts $header
150
+ puts "\n"
151
+ conf_init
152
+ 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
+
@@ -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'
@@ -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.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "whatisquiz/version"
2
+
3
+ module Whatisquiz
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Whatisquiz
2
+ VERSION = "1.0.7"
3
+ end
data/test/helper.rb ADDED
File without changes
File without changes
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'whatisquiz/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "whatisquiz"
8
+ spec.version = Whatisquiz::VERSION
9
+ spec.authors = ["chikyukotei"]
10
+ spec.email = ["takeme_imd1122@me.com"]
11
+ spec.summary = %q{unix command quiz}
12
+ spec.description = %q{unix command quiz}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whatisquiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - chikyukotei
@@ -41,10 +41,25 @@ dependencies:
41
41
  description: unix command quiz
42
42
  email:
43
43
  - takeme_imd1122@me.com
44
- executables: []
44
+ executables:
45
+ - whatisquiz
45
46
  extensions: []
46
47
  extra_rdoc_files: []
47
- files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/whatisquiz
55
+ - lib/color.rb
56
+ - lib/default_config
57
+ - lib/read_config.rb
58
+ - lib/whatisquiz.rb
59
+ - lib/whatisquiz/version.rb
60
+ - test/helper.rb
61
+ - test/test_whatisquiz.rb
62
+ - whatisquiz.gemspec
48
63
  homepage: ''
49
64
  licenses:
50
65
  - MIT
@@ -69,5 +84,7 @@ rubygems_version: 2.4.5
69
84
  signing_key:
70
85
  specification_version: 4
71
86
  summary: unix command quiz
72
- test_files: []
87
+ test_files:
88
+ - test/helper.rb
89
+ - test/test_whatisquiz.rb
73
90
  has_rdoc: