read_time_estimator 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rbenv-gemsets +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/read_time_estimator.rb +62 -0
- data/lib/read_time_estimator/version.rb +3 -0
- data/read_time_estimator.gemspec +24 -0
- data/spec/read_time_estimator_spec.rb +45 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2353f2fd643db245a883f9a380c6a741de9f0352
|
4
|
+
data.tar.gz: 290ffab835538aeabdd2ebd80a4cb7d77aeff0d2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2c17e0e77b44480ee21e3e2a8e32e6702d1adfcd827ab8aa66e15b98987a1738e3cbfda19b6a58e3a5b394c8eb3bb173671f5fa290e7929680df7293835cb748
|
7
|
+
data.tar.gz: 6420f523562c0a9a7cce8aa7a39503c37693dc8aa7c67e3bc9feabb6804f969bc6f5c59c827358ac36ce57e04fb26073df6cf127fd2f54b02b474f208fe3f4de
|
data/.gitignore
ADDED
data/.rbenv-gemsets
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
read-time-estimator
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.0-p247
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Abby Ihrig
|
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,29 @@
|
|
1
|
+
# ReadTimeEstimator
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'read_time_estimator'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install read_time_estimator
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( http://github.com/<my-github-username>/read_time_estimator/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "read_time_estimator/version"
|
2
|
+
|
3
|
+
module ReadTimeEstimator
|
4
|
+
module String
|
5
|
+
def minutes_to_read
|
6
|
+
self.split(' ').count/250.0
|
7
|
+
end
|
8
|
+
|
9
|
+
def read_time_words
|
10
|
+
time = minutes_to_read
|
11
|
+
words = []
|
12
|
+
if read_time_hours(time)
|
13
|
+
words << read_time_hours(time)
|
14
|
+
time = time % 60
|
15
|
+
end
|
16
|
+
if read_time_minutes(time)
|
17
|
+
words << read_time_minutes(time)
|
18
|
+
time = time % 1
|
19
|
+
end
|
20
|
+
if read_time_seconds(time)
|
21
|
+
words << read_time_seconds(time)
|
22
|
+
end
|
23
|
+
words << "1 second" if words.empty?
|
24
|
+
words = words.reverse
|
25
|
+
words.insert(2, ", ") if words[2]
|
26
|
+
words.insert(1, " and ") if words[1]
|
27
|
+
words = words.reverse
|
28
|
+
words.join + " to read"
|
29
|
+
end
|
30
|
+
|
31
|
+
def read_time_hours(time)
|
32
|
+
hours = (time/60).to_i
|
33
|
+
hours >= 1 ? hours_in_words(hours) : nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def hours_in_words(hours)
|
37
|
+
hours == 1 ? "#{hours} hour" : "#{hours} hours"
|
38
|
+
end
|
39
|
+
|
40
|
+
def read_time_minutes(time)
|
41
|
+
minutes = time.to_i
|
42
|
+
minutes > 1 ? minutes_in_words(minutes) : nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def minutes_in_words(minutes)
|
46
|
+
minutes == 1 ? "#{minutes} minute" : "#{minutes} minutes"
|
47
|
+
end
|
48
|
+
|
49
|
+
def read_time_seconds(time)
|
50
|
+
seconds = (time * 60).to_i
|
51
|
+
seconds > 1 ? seconds_in_words(seconds) : nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def seconds_in_words(seconds)
|
55
|
+
seconds == 1 ? "#{seconds} second" : "#{seconds} seconds"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class String
|
61
|
+
include ReadTimeEstimator::String
|
62
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'read_time_estimator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "read_time_estimator"
|
8
|
+
spec.version = ReadTimeEstimator::VERSION
|
9
|
+
spec.authors = ["Abby Ihrig", "Ana Tighe"]
|
10
|
+
spec.email = ["abby@planetargon.com", "ana@planetargon.com"]
|
11
|
+
spec.summary = %q{Estimates amount of time required to read given content.}
|
12
|
+
spec.description = %q{Estimates amount of time required to read given content.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec", "~> 2.14"
|
24
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "read_time_estimator"
|
2
|
+
require 'rspec'
|
3
|
+
|
4
|
+
describe "ReadTimeEstimator" do
|
5
|
+
describe "minutes_to_read" do
|
6
|
+
it "should output an amount of time given the length of a word" do
|
7
|
+
text = "word " * 250
|
8
|
+
expect(text.minutes_to_read).to eql 1.0
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "read_time_words" do
|
13
|
+
it "returns the reading time in phrase form when there is an even number of minutes" do
|
14
|
+
text = "word " * 500
|
15
|
+
expect(text.read_time_words).to eql "2 minutes to read"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns the reading time in phrase form when there are seconds" do
|
19
|
+
text = "word " * 625
|
20
|
+
expect(text.read_time_words).to eql "2 minutes and 30 seconds to read"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "returns the reading time in phrase form when read time is an hour" do
|
24
|
+
text = "word " * 15000
|
25
|
+
expect(text.read_time_words).to eql "1 hour to read"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns the reading time in phrase form when read time include an hour, minutes, and seconds" do
|
29
|
+
text = "word " * 22550
|
30
|
+
expect(text.read_time_words).to eql "1 hour, 30 minutes and 12 seconds to read"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns a minimum read time if the calculation is less than a second" do
|
34
|
+
text = "word"
|
35
|
+
expect(text.read_time_words).to eql "1 second to read"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "hours_in_words" do
|
40
|
+
it "correctly pluralizes 'hour' when hours to read is greater than one" do
|
41
|
+
text = "word " * 30000
|
42
|
+
expect(text.read_time_words).to eql "2 hours to read"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: read_time_estimator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abby Ihrig
|
8
|
+
- Ana Tighe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-04-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.5'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.5'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '2.14'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '2.14'
|
56
|
+
description: Estimates amount of time required to read given content.
|
57
|
+
email:
|
58
|
+
- abby@planetargon.com
|
59
|
+
- ana@planetargon.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- .gitignore
|
65
|
+
- .rbenv-gemsets
|
66
|
+
- .ruby-version
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/read_time_estimator.rb
|
72
|
+
- lib/read_time_estimator/version.rb
|
73
|
+
- read_time_estimator.gemspec
|
74
|
+
- spec/read_time_estimator_spec.rb
|
75
|
+
homepage: ''
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.2.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Estimates amount of time required to read given content.
|
99
|
+
test_files:
|
100
|
+
- spec/read_time_estimator_spec.rb
|