wpm 0.1.3 → 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.
- checksums.yaml +4 -4
- data/.gitignore +53 -0
- data/.rubocop.yml +26 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/wpm +5 -0
- data/lib/wpm.rb +163 -0
- data/lib/wpm/quotes.yml +6 -0
- data/lib/wpm/version.rb +3 -0
- data/wpm.gemspec +31 -0
- metadata +21 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b316a32799f878d70826fa2425e120e2ca6dda8a9f0f4ece99e4e9e403e091d5
|
4
|
+
data.tar.gz: 0df7ec245d5b61be73c9fdfcd72360f6d266aa7c63187257400740b47ae1e00d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db8125deaaff7af54b8c03f3be4b6eb0056dab3a78636f8ac67b373c998e534cb928f2bdb4d15bced22e747d611db1c83856fb7a9b5cdabc31e7d23376696b42
|
7
|
+
data.tar.gz: 65cae662a78a69d876cd355c1dcdbd1665872baefd71b3995f14570406368837d797121142652acb6ca80b8e679d3d75e08036ce1ea17d998a8f6365c1bc315b
|
data/.gitignore
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
*
|
2
|
+
!/**/
|
3
|
+
!?*.*
|
4
|
+
|
5
|
+
# directories
|
6
|
+
.bundle/
|
7
|
+
_yardoc/
|
8
|
+
coverage/
|
9
|
+
doc/
|
10
|
+
pkg/
|
11
|
+
spec/reports/
|
12
|
+
tmp/
|
13
|
+
vendor/
|
14
|
+
|
15
|
+
# files
|
16
|
+
*.dump
|
17
|
+
*.log
|
18
|
+
*.mod
|
19
|
+
*.o
|
20
|
+
*.swp
|
21
|
+
*~
|
22
|
+
.DS_Store
|
23
|
+
.idea
|
24
|
+
.project
|
25
|
+
.rake*
|
26
|
+
.rake*
|
27
|
+
.ruby-*
|
28
|
+
.rvmrc
|
29
|
+
.secret
|
30
|
+
.yardoc
|
31
|
+
TODO.md
|
32
|
+
core.*
|
33
|
+
cscope.out
|
34
|
+
secrets.yml
|
35
|
+
tags
|
36
|
+
|
37
|
+
# don't ignore
|
38
|
+
!.gitignore
|
39
|
+
!Capfile
|
40
|
+
!Cheffile
|
41
|
+
!Gemfile
|
42
|
+
![MR]akefile
|
43
|
+
!bin/**/*
|
44
|
+
!exe/**/*
|
45
|
+
|
46
|
+
/.bundle/
|
47
|
+
/.yardoc
|
48
|
+
/_yardoc/
|
49
|
+
/coverage/
|
50
|
+
/doc/
|
51
|
+
/pkg/
|
52
|
+
/spec/reports/
|
53
|
+
/tmp/
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Layout/CommentIndentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Layout/LeadingCommentSpace:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Layout/SpaceAroundOperators:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Layout/SpaceAfterComma:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Layout/SpaceInsideBlockBraces:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Naming/MethodParameterName:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/Documentation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/FrozenStringLiteralComment:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Style/FormatStringToken:
|
26
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
wpm (0.2.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
benchmark-ips (2.7.2)
|
11
|
+
builder (3.2.4)
|
12
|
+
byebug (11.0.1)
|
13
|
+
minitest (5.14.0)
|
14
|
+
minitest-reporters (1.3.8)
|
15
|
+
ansi
|
16
|
+
builder
|
17
|
+
minitest (>= 5.0)
|
18
|
+
ruby-progressbar
|
19
|
+
rake (13.0.1)
|
20
|
+
ruby-progressbar (1.10.1)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
benchmark-ips
|
27
|
+
bundler (~> 2.0)
|
28
|
+
byebug (~> 11.0.1)
|
29
|
+
minitest (~> 5.0)
|
30
|
+
minitest-reporters (~> 1.3.8)
|
31
|
+
rake (~> 13.0.1)
|
32
|
+
wpm!
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 sergioro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Wpm
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wpm`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'wpm'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install wpm
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wpm.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
CLEAN.include ['**/.*.sw?', '**/*.gem', 'test/test.log']
|
7
|
+
|
8
|
+
task default: %i[test package]
|
9
|
+
task package: :clean
|
10
|
+
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.libs << 'lib' << 'test'
|
13
|
+
t.test_files = FileList['test/**/*_test.rb']
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wpm"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/wpm
ADDED
data/lib/wpm.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'io/console'
|
2
|
+
require 'wpm/version'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class WPMError < StandardError; end
|
6
|
+
|
7
|
+
class Array
|
8
|
+
def average
|
9
|
+
(reduce(:+).to_f/size).round(2)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module WPM
|
14
|
+
extend self
|
15
|
+
|
16
|
+
def race(args)
|
17
|
+
help if !(args & %w[-h --help]).empty?
|
18
|
+
|
19
|
+
parse_options(args) unless args.empty?
|
20
|
+
|
21
|
+
@max_length||=4000
|
22
|
+
|
23
|
+
@eot=0x03
|
24
|
+
@eof=0x04
|
25
|
+
|
26
|
+
if quotes.empty?
|
27
|
+
puts "No quotes with less than #{@max_length} characters found"
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
@color="\e[4;32m"
|
32
|
+
@no_color="\e[m"
|
33
|
+
|
34
|
+
@lines=quotes[rand(quotes.size)].chars.each_slice(term_width).map(&:join)
|
35
|
+
@line=0
|
36
|
+
@pos=0
|
37
|
+
|
38
|
+
# average length of English words
|
39
|
+
@word_length=5
|
40
|
+
|
41
|
+
@start_time=time
|
42
|
+
print_text
|
43
|
+
|
44
|
+
loop do
|
45
|
+
update_text
|
46
|
+
break if @line==@lines.size-1 and pos==@lines.last.size
|
47
|
+
end
|
48
|
+
|
49
|
+
save_wpm
|
50
|
+
puts "\nWPM: #{wpm}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def help
|
54
|
+
puts <<~eof
|
55
|
+
Usage: wpm [options]
|
56
|
+
|
57
|
+
Options:
|
58
|
+
-h show this message
|
59
|
+
-s print stats
|
60
|
+
-l [length] maximum string length
|
61
|
+
-q print quotes.yml path
|
62
|
+
eof
|
63
|
+
exit
|
64
|
+
end
|
65
|
+
|
66
|
+
def parse_options(args)
|
67
|
+
if args.first=='-s'
|
68
|
+
stats
|
69
|
+
exit
|
70
|
+
end
|
71
|
+
|
72
|
+
if args.first=='-q'
|
73
|
+
puts quotes_file
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
|
77
|
+
if args.shift=='-l' and args.first.to_i > 0
|
78
|
+
@max_length=args.first.to_i
|
79
|
+
return
|
80
|
+
end
|
81
|
+
|
82
|
+
puts "Unknown option"
|
83
|
+
bye
|
84
|
+
rescue => e
|
85
|
+
"Bad options. For help: `wpm -h`"
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
|
89
|
+
def stats
|
90
|
+
str=File.open(wpm_file).read
|
91
|
+
scores=str.split(" ").map(&:to_i).select.with_index{|e,i| i.odd?}
|
92
|
+
printf "%-20s %s", "Number of races:", "#{str.count("\n")}\n"
|
93
|
+
printf "%-20s %s", "Average speed (WPM):", "#{scores.average}\n"
|
94
|
+
end
|
95
|
+
|
96
|
+
def time
|
97
|
+
Time.now.to_i
|
98
|
+
end
|
99
|
+
|
100
|
+
def wpm
|
101
|
+
@lines.join(' ').size*60/((time-@start_time)*@word_length)
|
102
|
+
end
|
103
|
+
|
104
|
+
def wpm_file
|
105
|
+
"#{ENV['HOME']}/.wpm_history"
|
106
|
+
end
|
107
|
+
|
108
|
+
def save_wpm
|
109
|
+
open(wpm_file,'a') do |f|
|
110
|
+
f.puts "#{Time.now.strftime("%Y-%m-%d")} #{wpm}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def quotes
|
115
|
+
YAML.load(open(quotes_file))
|
116
|
+
.sort_by(&:length)
|
117
|
+
.select {|e| e.size<@max_length}
|
118
|
+
rescue => e
|
119
|
+
"Error while reading #{quotes_file}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def quotes_file
|
123
|
+
"#{__dir__}/wpm/quotes.yml"
|
124
|
+
end
|
125
|
+
|
126
|
+
def print_text
|
127
|
+
print "\r"+text.sub(/(.{#{pos}})/,"#{@color}\\1#{@no_color}")+"\r"
|
128
|
+
end
|
129
|
+
|
130
|
+
# width of the terminal
|
131
|
+
def term_width
|
132
|
+
IO.console.winsize.last
|
133
|
+
end
|
134
|
+
|
135
|
+
def update_text
|
136
|
+
system('stty raw -echo')
|
137
|
+
c=STDIN.getc
|
138
|
+
bye if c==@eof.chr or c==@eot.chr
|
139
|
+
carriage_return if @pos>=term_width-1
|
140
|
+
@pos+=1 if c==text[pos]
|
141
|
+
ensure
|
142
|
+
system('stty -raw echo')
|
143
|
+
print_text
|
144
|
+
end
|
145
|
+
|
146
|
+
def carriage_return
|
147
|
+
@pos=0
|
148
|
+
@line+=1
|
149
|
+
end
|
150
|
+
|
151
|
+
def text
|
152
|
+
@lines[@line]
|
153
|
+
end
|
154
|
+
|
155
|
+
def pos
|
156
|
+
@pos
|
157
|
+
end
|
158
|
+
|
159
|
+
def bye
|
160
|
+
puts "\nBye"
|
161
|
+
exit
|
162
|
+
end
|
163
|
+
end
|
data/lib/wpm/quotes.yml
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
- "Do nothing out of selfish ambition or vain conceit, but in humility consider others better than yourselves"
|
2
|
+
- "It's a funny thing, but people mostly have it backward. They think they live by what they want. But really, what guides them is what they're afraid of. What they don't want"
|
3
|
+
- "Roses are red, violets are blue"
|
4
|
+
- "The best way to learn programming is by reading open source code"
|
5
|
+
- "Emacs is a nice operating system, but I prefer UNIX"
|
6
|
+
- "Real programmers can write assembly code in any language"
|
data/lib/wpm/version.rb
ADDED
data/wpm.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/wpm/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "wpm"
|
5
|
+
spec.version = WPM::VERSION
|
6
|
+
spec.authors = ["sergioro"]
|
7
|
+
spec.email = ["yo@sergioro.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{Increase your typing speed}
|
10
|
+
spec.description = %q{Increase typing speed and keep track of WPM history}
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| 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", "~> 2.0"
|
24
|
+
spec.add_development_dependency "rake", "~> 13.0.1"
|
25
|
+
spec.add_development_dependency "benchmark-ips", ">= 0"
|
26
|
+
spec.add_development_dependency "byebug", "~> 11.0.1"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.3.8"
|
29
|
+
|
30
|
+
#spec.add_runtime_dependency "SOME_GEM", "~> VERSION"
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wpm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sergioro
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,10 +97,26 @@ dependencies:
|
|
97
97
|
description: Increase typing speed and keep track of WPM history
|
98
98
|
email:
|
99
99
|
- yo@sergioro.com
|
100
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- wpm
|
101
102
|
extensions: []
|
102
103
|
extra_rdoc_files: []
|
103
|
-
files:
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- exe/wpm
|
116
|
+
- lib/wpm.rb
|
117
|
+
- lib/wpm/quotes.yml
|
118
|
+
- lib/wpm/version.rb
|
119
|
+
- wpm.gemspec
|
104
120
|
homepage:
|
105
121
|
licenses:
|
106
122
|
- MIT
|
@@ -120,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
136
|
- !ruby/object:Gem::Version
|
121
137
|
version: '0'
|
122
138
|
requirements: []
|
123
|
-
rubygems_version: 3.0.
|
139
|
+
rubygems_version: 3.0.6
|
124
140
|
signing_key:
|
125
141
|
specification_version: 4
|
126
142
|
summary: Increase your typing speed
|