wpm 0.1.2 → 0.1.3

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: 158a929f6f3f743e3cc9c9076051602f01c9f21f26d735b211c0f284ab3b73d8
4
- data.tar.gz: ead5d4376702e5c97d1a0692aab75e77e1d82937b11998cf0c4e9b457a7a39cd
3
+ metadata.gz: cea5ea6d5cbf2eb692ea13f5304b555eef40caa289e27df5a179c9ae2fd1b624
4
+ data.tar.gz: 21374c4ef47a836da034c3460ee1aabd313f313eff9c8a9b54b7291ee27ddd00
5
5
  SHA512:
6
- metadata.gz: 4c93099c3bbb63f542d900915ca112942be120f0b354e47d2b5ef9cb5550fee5916abd023e07ed17a9878c2131f6fb40dcebdfdc2a5ed28724242d58c94247a3
7
- data.tar.gz: 317d4a8c2296efa8b6056d43231eff1487da0ca0883047cc0ec1c301d0543495c19dbd0f7b38aee3a0f43abc9891b195236ddfcb96567c1e2bdff7d3e42bbb5c
6
+ metadata.gz: 5b43385d0fb20f0a4315ac180886038f878d19c1be2859c7b0fc69acfdc8eedf3c3134d605e570aad71190223167d434de2e7baff04e97be2bf1b9aca9212443
7
+ data.tar.gz: 361132347b94f368992217f031089a31b1c7e8adae90b2c08891b7ca3c0bbbd19344f37eeff3d4f5a31d12e98bbf6b78fc2df0cb296818e499273feb9802af7b
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.1.2
4
+ version: 0.1.3
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-14 00:00:00.000000000 Z
11
+ date: 2020-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,26 +97,10 @@ dependencies:
97
97
  description: Increase typing speed and keep track of WPM history
98
98
  email:
99
99
  - yo@sergioro.com
100
- executables:
101
- - wpm
100
+ executables: []
102
101
  extensions: []
103
102
  extra_rdoc_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
103
+ files: []
120
104
  homepage:
121
105
  licenses:
122
106
  - MIT
@@ -136,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
120
  - !ruby/object:Gem::Version
137
121
  version: '0'
138
122
  requirements: []
139
- rubygems_version: 3.0.6
123
+ rubygems_version: 3.0.3
140
124
  signing_key:
141
125
  specification_version: 4
142
126
  summary: Increase your typing speed
data/.gitignore DELETED
@@ -1,53 +0,0 @@
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 DELETED
@@ -1,26 +0,0 @@
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 DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.6.4
6
- before_install: gem install bundler -v 2.1.4
data/Gemfile DELETED
@@ -1,5 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in wpm.gemspec
4
- gemspec
5
-
data/Gemfile.lock DELETED
@@ -1,35 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- wpm (0.1.2)
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 DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,40 +0,0 @@
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 DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,14 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
data/exe/wpm DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "wpm"
4
-
5
- WPM.race(ARGV)
data/lib/wpm/quotes.yml DELETED
@@ -1,6 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- module WPM
2
- VERSION = "0.1.2"
3
- end
data/lib/wpm.rb DELETED
@@ -1,163 +0,0 @@
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/wpm.gemspec DELETED
@@ -1,31 +0,0 @@
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